运用<nav>链接滚动到页面响应局部
发布时间:09/01 来源:未知 浏览:
关键词:
下面是详细的代码
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>
本篇文章到这里就已经全部完毕了,更多出色内容大家可以关注PHP中文网的HTML视频教程栏目!!!
以上就是使用<nav>链接滚动到页面响应部分的具体内容,更多请关注百分百源码网其它相关文章!