gpt4 book ai didi

javascript - 用鼠标滚轮停止平滑滚动

转载 作者:行者123 更新时间:2023-11-30 17:41:21 25 4
gpt4 key购买 nike

我有这段代码,这样当点击一个 URL 时, View 将平滑地滚动到那个特定的 div(同一页面)。但是,我遇到了一些问题。
假设我点击了 URL,它现在平滑地滚动到页面底部。但是,当我尝试使用鼠标滚轮停止平滑滚动时却没有用。相反,它让我看起来有点像 buggy 。

代码如下请指教

        <script>
$('a').click(function(e){

$('html, body').stop().animate({
scrollTop: $( $(this).attr('href') ).offset().top
}, 1500);

return false;
});
</script>

最佳答案

试试这个

<script>
$('html, body').bind('mousewheel', function(e){
$(this).stop();
});

$('a').click(function(e){
$('html, body').stop().animate({
scrollTop: $( $(this).attr('href') ).offset().top
}, 1500);

return false;
});
</script>

关于javascript - 用鼠标滚轮停止平滑滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21026382/

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