Im trying to find the best way of animating a list of items one by one.
So for example I have a UL with 7 items in it and when my trigger element is clicked I want each item to fade in one below the other with a slight delay between each item.
Any ideas would be most appreciated.
Thanks
You can use pseudo-recursion:
function fadeItem() {
$('ul li:hidden:first').fadeIn(fadeItem);
}
This will fade in the first hidden item, and call itself when the animation finishes, fading the second item.
After it fades in the last item, the selector won't match anything, so it'll stop.
To add a delay between each fade, you can call jQuery's delay
method, like this:
function fadeItem() {
$('ul li:hidden:first').delay(500).fadeIn(fadeItem);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With