i've being trying to change the src of a img tag in order to create some kind of a sequence of images.
the code seems to work, but runs too fast,setTimeout does't look to do anything. if I replace this with this codeCode:<script type="text/javascript"> var i=0; function r() { i++; if(i==4){e=1;} var src = "img-" + e + ".jpg"; //images are sorted by number (img-1,img2...) this.src = src; setTimeout(r.call(this),2000); } </script> .... <input type="button" onclick="r.call(document.getElementById('impar'));"> <div><img id="impar" src="" ></div>
everything works fine.i know call is not the very right thing to been used, but i don't understand why setTimeout dosn't work. some clue?Code:<script type="text/javascript"> var i=0; var f=null; function r() { i++; if(i==4){e=1;} var src = "img-" + e + ".jpg"; foo.src = src; setTimeout(r,2000); } function init(a){ f=a; r(); } </script> .... <input type="button" onclick="init(document.getElementById('impar'));"> <div><img id="impar" src="" ></div>


Reply With Quote

Bookmarks