设置jquery默认动画速度



我找不到任何文档。我只想设置jQuery的默认动画速度。类似这样的东西:

 $.setDefaultAnimationSpeed = 5000; //does not work
 $('elem').fadeIn(); // takes 5 seconds
 $('elem').animate({
     foo : bar
 }); // also takes 5 seconds

谢谢大家!

$.fx.speeds._default = 1000; // change to whatever your desired speed

$.fx.speeds.jojo = 1000; // adds your own speed object to jqueryspeed

参考:https://learn.jquery.com/effects/intro-to-effects/#jquery-fx

我不认为jquery中有这样的东西,但你可以尝试这样的

 defaultAnimationSpeed = 5000;  // declare a global variable
 $('elem').fadeIn(defaultAnimationSpeed); 
 $('elem').animate({foo : bar}, defaultAnimationSpeed);

因此,它将适用于任何使用它的地方,而且你可以很容易地更改它。你不需要在动画中到处改变。

最新更新