Skip to content

Instantly share code, notes, and snippets.

@juliocesar
Created December 20, 2009 23:28
Show Gist options
  • Save juliocesar/260691 to your computer and use it in GitHub Desktop.
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
// 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