Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$.each and animation confusion

Tags:

jquery

I am expecting when I go

$.each($(something).find(something), function(){
   $(this).delay(1000).fadeOut();
});

then for each matching element I get a second of delay before it is gone. but what I get is a second of delay and then it all fades out. its 3am and I can't think. please help

like image 729
Ali Habibzadeh Avatar asked Dec 06 '25 06:12

Ali Habibzadeh


1 Answers

This will work, call it with a jQuery object as a parameter:

function fadeAll(elems) {
    var i=-1;
    function next() {
        i = i+1;
        if (i < elems.length)
            $(elems[i]).delay(1000).fadeOut(next);
    }
    next();
}

You can see it at work here.

like image 96
interjay Avatar answered Dec 12 '25 08:12

interjay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!