Created
December 20, 2009 23:28
-
-
Save juliocesar/260691 to your computer and use it in GitHub Desktop.
Runs a method on each element of a collection, with x milliseconds of interval between each
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
// Instead of this -> http://gist.github.com/255851 | |
// Use the code below. It's a lot more straightforward. | |
$.fn.oneAtEachTime = function(method, args, after) { | |
var collection = this, index = 0; | |
(function(e) { | |
$(e)[method].apply($(e), args); | |
var closure = arguments.callee, next = collection.get(index++); | |
if (next) { setTimeout(function() { closure(next); }, (parseInt(after) || 1000)); }; | |
})(this.get(index)); | |
}; | |
// So for instance: | |
// <ul><li>Foo</li><li>Bar</li><li>Baz</li></ul> | |
// With styles like: | |
// ul li { display: none } | |
// You can go: | |
// $('ul li').oneAtEachTime('fadeOut', [], 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment