$ .each and confusion animations

I expect when I go

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

then for each matching element I get a second delay until it disappears. but what I get is a second of delay, and then it all disappears. its 3am and i cant think. please, help

+3
source share
3 answers

This will work, call it using the 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 .

+4
source

, , ? , $(this).fadeOut(1000);, ; delay(1000) , fadeOut().

+1

This should be the main idea:

var set = $(something).find(something);
var delayFade = function(){
     $(this).delay(1000).fadeOut(400, nextDelayFade);
};
var i = 0;
var nextDelayFade = function()
{
  if(i < set.length)
  {
    $(set[i++]).each(delayFade);
  }
};
nextDelayFade();
+1
source

Source: https://habr.com/ru/post/1740615/


All Articles