html 代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Template</title>
<!------------ Stylesheet Includes ------------>
<link rel="stylesheet" href="http://localhost:8000/library/bootstrap/5.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="version/0.0.2/css/ng-box.css">
</head>
<body>
<!------------ Page Styles ------------>
<style>
.div {
height: 50vh;
}
.item {
cursor: pointer;
}
#d1 {
background-color: var(--ng-red);
}
#d2 {
background-color: var(--ng-blue);
}
#d3 {
background-color: var(--ng-green);
}
</style>
<!------------ Dom Elements ------------>
<nav id="common-nav"></nav>
<header id="common-header"></header>
<main>
<section id="part">
<div class="box-container">
<!------------ Your Content ------------>
<ul class="dynamic-data sticky-top d-flex gap-5 py-3 fs-3 bg-white"></ul>
<div id="d1" class="div"></div>
<div id="d2" class="div"></div>
<div id="d3" class="div"></div>
</div>
</section>
</main>
<footer id="common-footer"></footer>
<!------------ Script Includes ------------>
<script src="http://localhost:8000/library/jquery/3.6.0/jquery.min.js"></script>
<script src="version/0.0.2/js/ng-box.js"></script>
<!------------ Page Scripts ------------>
<script>
const partDynamicDataTraverse = {
"$element": $("#part .dynamic-data"),
"list": [{
"href": "#d1",
"name": "skip1"
},
{
"href": "#d2",
"name": "skip2"
},
{
"href": "#d3",
"name": "skip3"
}
]
}
for (data of partDynamicDataTraverse.list) {
partDynamicDataTraverse.$element.append(`
<li><div class="item" href="${data.href}">${data.name}</div></li>
`)
}
</script>
</body>
</html>
需要通过给 .item 增加 href 属性来指定跳转的位置, 应该如何实现?
是这样吗?