我知道堆栈中有很多平滑的滚动脚本,过去我已经采用了很多。由于我不想使用<a href="#">
链接,因此我使用<buttons data-href="">
。这是我当前的代码:Smooth scroll to data-href
var $root = $('html, body');
$('.smooth').click(function() {
var href = $.attr(this, 'data-href');
$root.animate({
scrollTop: $(href).offset().top
}, 500, function() {
window.location.hash = href;
});
return false;
alert('smoothness');
});
和必要的HTML部分:
<button id="downarrow" data-href="#features" class="smooth">
<span>scroll down</span>
</button>
这个伟大的工程,因为看到这里:DEMO
我不知道为什么,但它在我的现场使用相同的代码不起作用。你可以在这里查看它的构建:
可能重复: http://stackoverflow.com/questions/3870057/how-can-i-update-window-location-hash-without-jumping-the-document。检查是否有帮助。 – krato