开发者

How to set default speed for specific jquery effect

I am learning how to make AJAX with jquery and found the way to do highlight effect:

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

Is there a way to make the 3000 default speed for the highlight effect so I don't have to repeat it in all locations?

I am aware that it's possible to change开发者_如何学C the default jquery fx speed, but that will change for all effects, I want to change the default only for a single effect.


You could write a simple wrapper for the effect that uses the default speed:

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


You could overwrite the effect function in jQuery UI:

(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);

Example: http://jsfiddle.net/j7Wns/1/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜