wait() or sleep() function in jquery?

前端 未结 7 688
醉酒成梦
醉酒成梦 2020-12-04 20:48

I want to add a class, wait 2 seconds and add another class.

.addClass(\"load\").wait(2sec).addClass(\"done\");

Is there any way?

相关标签:
7条回答
  • 2020-12-04 21:25

    There is an function, but it's extra: http://docs.jquery.com/Cookbook/wait

    This little snippet allows you to wait:

    $.fn.wait = function(time, type) {
        time = time || 1000;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $(self).dequeue();
            }, time);
        });
    };
    
    0 讨论(0)
提交回复
热议问题