Created
September 13, 2014 21:23
-
-
Save devcem/955d6cdbe465f550a9e2 to your computer and use it in GitHub Desktop.
Javascript sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
You can use it for animations or sequential processes. | |
*/ | |
function sequence(){ | |
var length = arguments.length-1; | |
var delay = arguments[length]; | |
for(i=0;i<length;i++){ | |
setTimeout( | |
(function(s) { | |
return function() { | |
s(); | |
} | |
})(arguments[i]), delay*i); | |
} | |
} | |
sequence( | |
function(){alert("First alert")}, | |
function(){alert("Second alert after 2 second")}, | |
function(){alert("And more...")}, | |
1000 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment