JQuery, using each () as classic for each loop, and not all at the same time

I am trying to loop through div tags and preempt them every time. Until now, using the .each () operator, he does them all at once. How do you use .each () as more classic for each loop?

Here is my jQuery code snippet and currently it is obscuring all div tags, not one by one.

$("document").ready(function() {   
// all div tags are hidden at start 

    $(".myclass").each(function (i) {
      var $div = $(this);
      showDiv($div);
      hideDiv($div);
});

function showDiv(theDiv)
{
      $(theDiv).fadeIn(4000);
}

function hideDiv(theDiv)
{
       $(theDiv).fadeOut(4000);
}     
});

Thank you for considering

+5
source share
3 answers

.each() for. , ( jQuery). .fadeIn() .fadeOut() , .

fadeIn(), -:

$("document").ready(function() {   
  var divs = $('.myclass'), i = 0;
  function reveal() {
    if (i === divs.length) return;
    divs.eq(i).fadeIn(4000, function() {
      divs.eq(i).fadeOut(4000, function() {
        i++;
        setTimeout(reveal, 0);
      });
    });
  }
  setTimeout(reveal, 0);
});
+2

:

var delay = 0;
$(".myclass").each(function (i) {
    var $div = $(this);
    showDiv($div);
    hideDiv($div, delay);
    delay += 100;
});


function hideDiv(theDiv, delay)
{
    $(theDiv).fadeOut(4000).delay(delay);
}   
+1

.each . , , Javascript . showDiv hideDiv . .

, jQuery, Javascript.

- :

function showHide(theDiv) {
     if( $(theDiv).is(":visible") ) {
          $(theDiv).fadeOut(4000);
     }
     else {
          $(theDiv).fadeIn(4000);
     }
}

setInterval( function() { showHide("#theDivsID") }, 4100 );
+1

All Articles