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'; } } };

31st Jul 2019, 2:25 AM
liu Mr.
liu Mr. - avatar
4 Antworten
0
px is unit pixels; >= is safer. but if you move only with pos+=1 you can check (pos=150) too
31st Jul 2019, 3:19 AM
zemiak
0
but when i change pos>=150to=150,it does'nt work
31st Jul 2019, 4:20 AM
liu Mr.
liu Mr. - avatar
0
liu Mr. It's supposed to be == for comparison not = since = is assignment
31st Jul 2019, 5:46 AM
Agent_I
Agent_I - avatar
0
Thank you all!My question is solved!
31st Jul 2019, 7:37 AM
liu Mr.
liu Mr. - avatar