I am attempting to track the movement of a dynamic div (which is animated using CSS3 animations) by continuously monitoring its position. To achieve this, I have implemented a loop utilizing while(true)
as shown below:
function detectCollision(){
alert(document.getElementById("obstacle").style.left)
while(true){
var temp = getObstaclePosition();
var temp2 = getPlanePosition();
if(temp[0] <= temp2[0]+500){
document.getElementsByClassName("plane")[0].style.display = "none";
break;
}
}
}
The issue arises after displaying the first alert since the page becomes unresponsive. Additionally, introducing an alert within the while loop results in continuous popping alerts but ensures that the code functions correctly. How can I address this problem?