javascript 如何控制jquery动画速度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11115509/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 12:07:25  来源:igfitidea点击:

how to control jquery animate speed

javascriptanimation

提问by Kashif Munir

i am working with jquery for animate a div. i want to control speed on moving. i played lot of with this. but i hope some one can tell me how can i control the speed. here is the code example.

我正在使用 jquery 为 div 设置动画。我想控制移动速度。我玩了很多这个。但我希望有人能告诉我如何控制速度。这是代码示例。

$(document).ready(function(){
    $('#block').css({'left':'-617px','top':'-300px'});
    $('#Cont').show();
    $('#block').animate({'left':'17px','top':'10px'},'slow',function(){

    });
});

i want to know how can i control the speed on animation.

我想知道如何控制动画速度。

回答by Fabrizio Calderan

just change slowwith the time in milliseconds, e.g. for 1,2 seconds just do

只需slow以毫秒为单位更改时间,例如 1,2 秒就可以了

$('#block').animate({'left':'17px','top':'10px'},  1200, function() {
...

回答by suraj

The default duration is 400 milliseconds. The strings 'fast' and 'slow' corresponds to 200 and 600 milliseconds, respectively.

默认持续时间为 400 毫秒。字符串 'fast' 和 'slow' 分别对应于 200 和 600 毫秒。

$('#block').animate({'left':'17px','top':'10px'},'slow',function(){


        });