gpt4 book ai didi

javascript - Smooth Scroll 跳跃而不是滚动

转载 作者:太空宇宙 更新时间:2023-11-04 13:10:00 31 4
gpt4 key购买 nike

我使用了 CSS TRICKS 的 Smooth Scroll Plugin,它工作得很好,但只有 2 个 ancoher 链接,而不是另一个链接,请在此处查看演示,

LIVE DEMO

它对行业和定价非常有用,但在推荐时它只是跳转到该位置,而且固定导航也切断了该部分。

<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/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com