Javascript with Class function

Asked

Viewed 31 times

0

Good,

I have the following code that runs a sequence of images:

 var setInter = null
 function startAnimation() {
     var frames = document.getElementById("animation").children;
     var frameCount = frames.length;
     var i = 0;
     setInter = setInterval(function () {
         frames[i % frameCount].style.display = "none";
         frames[++i % frameCount].style.display = "block";
         if(i>=18){ 
             clearInterval(setInter);
         }
     }, 100);
 }

This runs an animation by frames, and when the condition happens, that is 19 frames, the animation stops.

I want the animation to happen when the div #Animation has the class "in-view". This part is already taken, and when I scroll to the div, it gains the class "in-view", however I do not arrange form of the function activate and animation happen.

Solutions other than Jquery.

Thank you!

  • 1

    How’s the code that adds the class in-view? I would have been able to put him in your question?

  • When you scroll up to the div, you can’t call the function startAnimation()?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.