gpt4 book ai didi

jquery - 为什么 jQuery 平滑滚动在页面上跳动?

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

我在以下页面上有一个 jQuery 平滑滚动:

http://test4.coretechs.com/coretechs_site/promo-test

当您单击其中一个导航项时,它将动画滚动到 <div id=''>对于该导航项。动画滚动有效,但大多数情况下,在滚动发生之前页面会跳转。

我在 Firefox 和 Chrome 中遇到了这个问题。

有谁知道为什么会发生这种跳跃?

最佳答案

尝试 event.preventDefault()

$("ul.menu a.promonav_services, ul.menu a.promonav_portfolio, ul.menu a.promonav_contact").click(function (e) {
e.preventdefault(); //stop the default behavior of anchor tag
var href = $(this).attr('href').replace('#', '');
scrollToAnchor(href);
});

关于jquery - 为什么 jQuery 平滑滚动在页面上跳动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21963423/

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