Robert Marić Robert Marić - 1 month ago 11
Javascript Question

Q: How do I make each div fade away individually?

So I have JSON object and I have to make that each div fades away by the number of their age.

The code so far!

Answer
  function animBox(div, age){

   setTimeout(function(){ 

         var int = setInterval(function() {

      var opacity = div.style.opacity;

      if(opacity != "0") {     
        div.style.opacity = opacity ? (parseFloat(opacity) - 0.1) : 1;
      }

     }, 100);
   }, age * 100);

  }

}

Hope this will help you :)

Comments