javascript - Confused with set timeout -
i'm confused how these work...the timeout not seem keep running calls begin_anim
once , thats it....
so hoping can see went wrong , explain how implement this?
this code:
//test data: //type = 'up'; //div = document.getelementbyid('theid'); //marginl = -400; function timeout_begin(type,div,marginl){ settimeout(begin_anim(type,div,marginl),1000); } function begin_anim(type,div,marginl){ if(type == 'up'){ if(marginl >= '-200'){ if(marginl > '-200'){ div.style.marginleft = '-200px'; } return false; } marginl += 2; div.style.marginleft = marginl+'px'; } return false; }
hope can help!
you're looking setinterval!
also, it's better pass actual function in, , can hold reference loop can stop running later if want to:
var animationloop = setinterval(function () { begin_anim(type, div, marginl); }, 1000); clearinterval(animationloop); // stop loop.
Comments
Post a Comment