Set HTML <img> element to Javascript image variable -


i have array of image variables preloaded using javascript make image sequence animation. issue have setting img element html use 1 of these images. seems properies strings?

here's how set array of images in javascript:

for(var = 0; < 30; ++){     anim[i] = new image();     if(i < 10){         anim[i].src = "images/anim/frame0" + + ".png";     }     if(i >= 10){         anim[i].src = "images/anim/frame" + + ".png";     } } 

and have ^img tag = "animation"^ in html want change.

your code looks valid.

for(var = 0; < 30; i++){     anim[i] = new image();      if(i < 10){         anim[i].src = `images/anim/frame0${i}.png`;     }      if(i >= 10){         anim[i].src = `images/anim/frame${i}.png`;     } } 

now can do: document.body.appendchild(anim[0]);

i tested , works me.

if want change src on fly you'd have select appended element , update src this: document.queryselectorall('img')[0].src = newsourcevariable;.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -