如何设置默认速度为特定的jQuery效果

问题描述:

我正在学习如何让AJAX使用jQuery,发现做高亮效果的方式:如何设置默认速度为特定的jQuery效果

$("#main_table > tbody > tr:first").effect('highlight', {}, 3000) 

有没有一种方法,使3000的默认速度为亮点效果,所以我不必在所有地点重复它?

我知道可以更改默认的jquery fx速度,但对于所有效果都会更改,我只想更改单个效果的默认值。

你可以写一个使用默认速度的影响一个简单的包装:

function highlight(elems){ 
    elems.effect("highlight", {}, 3000) 
} 

你可以在jQuery UI的覆盖effect功能:

(function($) { 
    $.fn.extend({ 
     _effect: $.fn.effect, // backup the original function 
     effect: function(effect, options, speed, callback) { 
      if (effect === 'highlight') speed = 3000; 

      // compose the arguments 
      var args = [effect, options || {}]; 
      if (speed !== undefined) args.push(speed); 
      if (callback !== undefined) args.push(callback); 

      // call the original function 
      return this._effect.apply(this, args); 
     } 
    }); 
})(jQuery); 

例子:http://jsfiddle.net/j7Wns/1/