jQuery showeach() plugin
I needed a recursive way to show each item in set, after the previous item had been shown. I came up with this:
/**
* copyright 2007 Woody Gilk
*
* You may use this for whatever you want, provided this copyright
* message remains intact and unaltered.
*/
jQuery.fn.showeach = function(speed){
var speed = speed || 'normal';
var self = jQuery(this);
var next = self.next();
// Run show(), with a callback to showeach() on the next sibling
self.animate({width: 'toggle'}, speed, 'backout', function(){
next.showeach(speed);
});
return this;
}
Example:
$('#menu li').eq(0).showeach('fast');
Note that you need to use .eq(0), or some kind of modifier, like :first to ensure that you only pass one element to showeach.
Comments
2 Responses to “jQuery showeach() plugin”
Leave a Reply
Based upon this, I developed a similar plugin, that works for any type of animation:
http://dev.jquery.com/~john/plugins/anistack/
It even works for non-animation stuff like click or load.
I won’t pretend to understand the code that actually drives .stack(), but it’s enough to say that John Resig is the man.