简体   繁体   English

如何更改站点范围的jQuery slideUp / slideDown持续时间?

[英]How to change site-wide jQuery slideUp/slideDown duration?

Is there a way to adjust the default slideUp() and slideDown() duration in jQuery? 有没有办法在jQuery中调整默认的slideUp()和slideDown()持续时间? I have a site which has a bunch of slideUp/slideDown calls and I'd like to change their duration site-wide. 我有一个网站有一堆slideUp / slideDown调用,我想在网站范围内更改他们的持续时间。 The only options I can find: 我能找到的唯一选择:

  • Regex search and replace across all of my JS code. 正则表达式搜索并替换我的所有JS代码。 Possible, and I can insert a variable to change the duration again later. 可能,我可以插入一个变量以便稍后再次更改持续时间。 But it would be more convenient if there were a jQuery setting, especially to reduce testing time. 但是如果有jQuery设置会更方便,特别是为了减少测试时间。
  • Edit jQuery itself. 编辑jQuery本身。 Not a viable option for maintenance reasons. 出于维护原因,这不是可行的选择。

You can change the default animation speed like this: 您可以像这样更改默认动画速度:

$.fx.speeds._default = 1000;

Important Note: I think this will change the default speed for every jQuery animation, which may not be ideal in this case. 重要说明:我认为这将改变每个jQuery动画的默认速度,在这种情况下可能不是理想的。

You could override them like: 您可以覆盖它们,如:

$.prototype.slideDown = (function(slideDown){
    var defaultSpeed = 2000;
    return function(speed){
        slideDown.call( this, speed || defaultSpeed );
    };
})($.prototype.slideDown);

Then just do the same with the slideup function: 然后用幻灯片功能做同样的事情:

$.prototype.slideUp = (function(slideUp){
    var defaultSpeed = 2000;
    return function(speed){
        slideUp.call( this, speed || defaultSpeed );
    };
})($.prototype.slideUp);

Then just call it: 然后就叫它:

$('#whatever').slideUp();

Just make sure to override them before you start using them. 只需确保在开始使用它们之前覆盖它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM