+ 3
Can some pls explain this else statement to me
var pos = 0; //our box element var box = document.getElementById("box"); var t = setInterval(move, 10); function move() { if(pos >= 150) { clearInterval(t); } else { pos += 1; box.style.left = pos+"px"; } }
3 Réponses
+ 1
It adds 1 to "pos" and adds a CSS attribute to #box with the "pos" in pixels.
+ 7
firstly we set pos to one. then select element with id box. then me use setIterval function i.e call a function after some time given by user. as in example its call move function .01 sec(1000= 1 second).
and in our function move. their is condtion that check if our pos value is 150 or more than then perform clearInterval function ( clear function is used to stop setInterval )
and in else if we don't reach at 150 then add 1 into position and also add left 1pixel to position of box.
hope you understand
0
thanks a lot