gpt4 book ai didi

javascript - jquery 动画速度没有改变

转载 作者:行者123 更新时间:2023-11-28 07:19:45 28 4
gpt4 key购买 nike

我正在使用按钮单击事件向下滚动整个页面。当我更改 jquery animate() 函数的持续时间参数时,速度似乎没有改变。我做错了什么?

这是我的代码:

    $("#arrowdown").click (function(){
$("html, body").animate(
{
scrollTop: $("#second-page").offset().top
},
100//no matter how I changed here, the speed haven't change at all.
);
})

最佳答案

前段时间我写了一些与此非常相似的代码,虽然你没有说#arrowdown 元素是一个链接,但我敢打赌它是指向#second-page (href = '#second -page') 如果是这种情况,它会直接跳到页面下方,根本没有动画。

试试这个:

$("#arrowdown").click (function(e){
e.preventDefault();
$("html, body").animate(
{
scrollTop: $("#second-page").offset().top
},
1000
);
})

最大的变化是 function(e)e.preventDefault(); 这将防止默认操作覆盖您想要发生的事情。

关于javascript - jquery 动画速度没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32146885/

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