Skip to content

Instantly share code, notes, and snippets.

@bittersweetryan
Last active December 14, 2015 21:59
Show Gist options
  • Save bittersweetryan/5154945 to your computer and use it in GitHub Desktop.
Save bittersweetryan/5154945 to your computer and use it in GitHub Desktop.
$(function(){
var div = $( '#doStuff' );
//add the delay to the queue
div.delay( 1000, 'myQ')
.queue( 'myQ', function(){
//this still refers to the current element
$( this ).prepend( '<p>Waited 1 second</p>' )
.find('p')
.fadeIn()
//invoke the next element in the queue
.end().dequeue( 'myQ' );
} )
.delay( 500, 'myQ' )
.queue( 'myQ', function(){
$( this ).prepend( '<p>Waited .5 more seconds</p>' )
.find('p')
.fadeIn()
.end().dequeue( 'myQ' );
} )
.delay( 1000, 'myQ')
.queue( 'myQ', function(){
$( this ).prepend( '<p>Waited 1 more seconds</p>' )
.find('p')
.fadeIn();
});
//start removing items from the queue
div.dequeue( 'myQ' );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment