javascript - setTimeout firing twice in this code? -


so have got code.

var x = 0;  function main() {     console.log("window load occurred!");     console.log('imgchild log!');     var firstchildren = $('.imgchild');     var arrchildren = [];     (var = 0, l = firstchildren.length; < l; += 3) {         arrchildren.push(firstchildren.slice(i, + 3));     }     console.log(firstchildren);     console.log(arrchildren);     arrchildren[0].fadein();     var length = arrchildren.length;  function myanim() {     // debugger;     console.log('timeout log');     console.log(x);     arrchildren[x].animate({         left: '-100%'     }, function() {         arrchildren[x].hide().animate({             left: '0%'         }).css('top', '0');         x++;         console.log(x);         arrchildren[x].css({             top: '0px',             left: '100%'         }).show().animate({             left: '0%'         });         settimeout(myanim, 3000);     }); } settimeout(myanim, 3000); }  $(window).on('load', main); 

as can guess when window loads, main function invoked. after creating proper arrays sets timer. myanim function invoked console should log logic ... 'timeout log', 0 (the x), 1 (the x after x++) , should move next timeout. after logging 1 see console log 2 if x++ done twice. why happening? how can fix it? did research , turns out settimeout fires twice, cannot figure how fix in case.


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -