Created
December 14, 2009 07:01
-
-
Save juliocesar/255851 to your computer and use it in GitHub Desktop.
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
// Say we got: <ul> <li>Foo</li> <li>Bar</li> </ul> | |
// Fade list entries one by one, with a 200ms interval | |
// | |
// $.withChildren('ul:first', 'li', 'fadeOut', [], 200) | |
// | |
;(function($) { | |
$.withChildren = function(element, childSelector, _method, args, after) { | |
var childTag = childSelector || {'DIV': 'div', 'UL': 'li'}[$(element).get(0).tagName] || 'div'; | |
var children = $(element).find('> ' + childTag); | |
(function(e) { | |
$(e)[_method].apply($(e), args); | |
var self = arguments.callee; | |
if ($(e).next().length) { setTimeout(function() { self($(e).next()); }, (parseInt(after) || 1000)); }; | |
})(children[0]); | |
}; | |
})(jQuery); | |
// *cough* documentation: | |
// $.withChildren(<selector for finding child nodes>, <method called on children>, <arguments for method>, <interval>) | |
// | |
// Pluginize it | |
$.fn.withChildren = function(childSelector, _method, args, after) { | |
return this.each(function() { $.withChildren(this, childSelector, _method, args, after) }); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment