0

So I have an image

<img id="animation" onload="initAnimation()" src='run-1.png'>

And I want to animate the image using run-2.png, run-3.png, etc. Using Javascript,

var imageAnimation = document.getElementById('animation');
var images = ['run-1.png','run-2.png','run-3.png','run-4.png','run-5.png'];
var currentIteration = 0;


function initAnimation(){
  animate();
}

function animate(){
  for(i=0; i<images.length; i++){
      imageAnimation.src = images[i]
    }
    animate();
}

But I can't seem to get the code to trigger. Do you see anything wrong with my code? My question is different than the checking for when the image has finished loading because I need to loop through many images.

hippoman
  • 187
  • 2
  • 10
  • Possible duplicate of [How to create a JavaScript callback for knowing when an image is loaded?](https://stackoverflow.com/questions/280049/how-to-create-a-javascript-callback-for-knowing-when-an-image-is-loaded) – holydragon Feb 26 '19 at 10:48
  • I guess this link will help you http://css3.bradshawenterprises.com/cfimg/ – Elbek Feb 26 '19 at 10:58

0 Answers0