我使用了 CSS TRICKS 的 Smooth Scroll Plugin, 它工作得很好,但只有 2 个 ancoher 链接,而不是另一个链接,请在此处查看演示,
它对行业和定价非常有用,但在推荐时它只是跳转到该位置,而且固定导航也切断了该部分。
<script>
$(document).ready(function () {
$('a[href^="#"]').on('click', function (e) {
e.preventDefault();
var target = this.hash,
$target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top - 130 // - 130px (nav-height)
}, 900, 'swing', function () {
// Replace this with something that can be easily parsed and used by your code
window.location.hash = '3' + target;
});
});
});
</script>
最佳答案
我在这里做了一个 jsfiddle,
jsfiddle.net/Thq62/
它工作正常,只是向链接添加了正确的 id 和散列
关于javascript - Smooth Scroll 跳跃而不是滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24756648/