문제

JavaScript:

var chop1 = document.getElementById("chop1");
var hit = document.getElementById("butn");
chop1.style.position = "relative";
chop1.style.top = "0px";
var chopperY;
function fly() 
 {

chop1.style.top = parseInt(chop1.style.top ) + 10 + 'px';
chopperY = chop1.style.top;
if( chopperY  == 500)
    {
  alert("get the position")
     }
requestAnimationFrame(fly);

};
hit.onclick = function()
{
  fly();
};

In the above example nothing is alerted at chopperY == 500.Console doesn't give any error.What is error in this code?How to alert that string at the given condition?

도움이 되었습니까?

해결책

The style.top property of an HTML node is always a string containing both the position and the unit (in your case it would be a 'px'), so in your conditional statement you should rather write if (chop1 === '500px') {...}.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top