0
what is the"px"?why the pos>=150not =150?
window.onload = function() { 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'; } } };
4 Antworten
0
px is unit pixels;
>= is safer. but if you move only with pos+=1 you can check (pos=150) too
0
but when i change pos>=150to=150,it does'nt work
0
liu Mr.
It's supposed to be == for comparison not = since = is assignment
0
Thank you all!My question is solved!