
Coffeescript:
$("nav").find("a").click (e) ->
e.preventDefault()
section = $(this).attr "href"
$("html, body").animate
scrollTop: $(section).offset().top或JS:
$("nav").find("a").click(function(e) {
e.preventDefault();
var section = $(this).attr("href");
$("html, body").animate({
scrollTop: $(section).offset().top });});和一些示例HTML
<nav>
<a href="#welcome">Welcome</a>
<a href="#about">About</a>
<a href="#section3">Section 3</a>
</nav>
<div id="welcome">Welcome to this website</div>
<div id="about">About this website, and such</div>
<div id="section3">The third section</div>以上就是如何使用<nav>链接实现滚动到页面某一部分的详细内容,
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)