随着单页网站的出现,使用滚动作为导航长页面的方法越来越流行。这个小部分是用JS+jQuery代码实现的,你可以很方便的在nav元素中设置链接滚动到页面的相应部分。如果您希望在不存在JS时将锚标记添加到页面。Coffeescript:$("nav").find("a").click(e)->e.preventDefault()section=$(this).attr"href"$("html,body").animatescrollTop:$(section).offset().top或JS:$("nav").find("a").click(function(e){e.preventDefault();varsection=$(this).attr("href");$("html,body").animate({scrollTop:$(section).offset().top});});和一些示例HTML
