Javascript setInterval unwanted pause -
i trying create animation few images in javascript , have code working, after runs through images in reverse pauses before starts going forward again. i'm wondering how rid of pause?
here code in action http://isogashii.com/projects/javascript/ch10/dp10-6.html
html
<img id="pin" src="assets/pin0.gif" alt="pin animation" />
javascript
var pin = new array(9); var curpin = 0; var x = false; // caching images (var imagesloaded=0; imagesloaded < 9; ++imagesloaded) { pin[imagesloaded] = new image(); pin[imagesloaded].src = "assets/pin" + imagesloaded + ".gif"; //starts pinf function when images cached if (imagesloaded == 8) { setinterval("pinf()", 120); } } function pinf() { if (x == true) { --curpin; if (curpin == 0) { x = false; } } if (x == false) { ++curpin; if (curpin == 8) { x = true; } } document.getelementbyid("pin").src = pin[curpin].src; }
in x == true
portion of if statement, should set curpin 1 otherwise duplicating curpin = 1.
function pinf() { if (x == true) { --curpin; if (curpin == 0) { curpin = 1; x = false; } } if (x == false) { ++curpin; if (curpin == 8) { x = true; } } document.getelementbyid("pin").src = pin[curpin].src; }
Comments
Post a Comment