🌐 AI搜索 & 代理 主页
Skip to content

Commit bbd933c

Browse files
committed
Added in the .delay() method for delaying the execution of queued functions and animations.
1 parent d42afd0 commit bbd933c

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/data.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,21 @@ jQuery.fn.extend({
166166
jQuery.dequeue( this, type );
167167
});
168168
},
169+
170+
// Based off of the plugin by Clint Helfers, with permission.
171+
// http://blindsignals.com/index.php/2009/07/jquery-delay/
172+
delay: function( time, type ) {
173+
time = jQuery.fx ? jQuery.fx.speeds[time] || time : time;
174+
type = type || "fx";
175+
176+
return this.queue( type, function() {
177+
var elem = this;
178+
setTimeout(function() {
179+
jQuery.dequeue( elem, type );
180+
}, time );
181+
});
182+
},
183+
169184
clearQueue: function(type){
170185
return this.queue( type || "fx", [] );
171186
}

test/unit/data.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,21 @@ test("queue() passes in the next item in the queue as a parameter to fx queues",
257257

258258
});
259259

260+
test("delay()", function() {
261+
expect(2);
262+
stop();
263+
264+
var foo = jQuery({}), run = 0;
265+
266+
foo.delay(100).queue(function(){
267+
run = 1;
268+
ok( true, "The function was dequeued." );
269+
start();
270+
});
271+
272+
equals( run, 0, "The delay delayed the next function from running." );
273+
});
274+
260275
test("clearQueue(name) clears the queue", function() {
261276
expect(1);
262277

0 commit comments

Comments
 (0)