HTML 页面
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<a id="a">跳到 div1</a>
<div id="div1">div1</div>
</body>
</html>
用animate属性,当点击锚点后,页面滚动到相应的DIV
<script type="text/javascript" src="引用js.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#a").click(function() {
$("html, body").animate({
scrollTop: $("#div1").offset().top }, {duration: 500,easing: "swing"});
return false;
});
});
</script>
$("html, body")可以替换为响应的div,如果不起作用,试着给该div增加overflow:scroll属性。
页面内锚点定位及跳转方法
最新推荐文章于 2023-08-16 10:17:42 发布