过度锚点定位(H5+JS/jQuery)
作者:互联网
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>过度锚点定位</title>
</head>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script>
$(function () {
$('a[href*=#],area[href*=#]').click(function () {
console.log(this.pathname)
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
if ($target.length) {
var targetOffset = $target.offset().top;
$('html,body').animate({
scrollTop: targetOffset
},
1000);
return false;
}
}
});
})
</script>
<style type="text/css" media="screen">
.mk {
height: 500px;
width: 980px;
border: 1px solid #999;
margin: auto;
}
.evt_nav_right {
position: fixed;
top: 100px;
right: 10px;
width: 100px;
}
.evt_nav_right a {
display: inline-block;
width: 100px;
}
</style>
<body>
<div class="evt_nav_right" style="visibility: visible;">
<a ytag="20054" href="#mk01" class="evt_link1" title="老乔经典">2</a>
<a ytag="20055" href="#mk02" class="evt_link2" title="实时爆款">3</a>
<a ytag="20056" href="#mk03" class="evt_link3" title="热销推荐">4</a>
<a ytag="20057" href="#mk04" class="evt_link4" title="主流配件">5</a>
<a ytag="20058" href="#mk05" class="evt_link5" title="更多活动">6</a>
<a ytag="20059" href="javascript:void(0);" class="evt_link0" title="返回顶部"></a>
</div>
<div class="mk" id="mk01"><img src="../PublicImg/Number/2.jpg" /></div>
<div class="mk" id="mk02"><img src="../PublicImg/Number/3.jpg" /></div>
<div class="mk" id="mk03"><img src="../PublicImg/Number/4.jpg" /></div>
<div class="mk" id="mk04"><img src="../PublicImg/Number/5.jpg" /></div>
<div class="mk" id="mk05"><img src="../PublicImg/Number/6.jpg" /></div>
</body>
</html>
标签:jQuery,right,target,100px,targetOffset,JS,width,pathname,锚点 来源: https://blog.csdn.net/qq_43003203/article/details/121523458