Cant stop an object.
Hello,
I’ve been trying to make an item move on onload. I want to stop it if b – c = 10%. Below is my code. Thanks
function move() {
var enem = document.getElementById("2");
var elem = document.getElementById("1");
var width = 1;
var enemwidth = enem.style.left;
var id = setInterval(frame, 100);
var dif = enem.style.left - elem.style.left;
function frame() {
if (enem.style.left - elem.style.left == '10%') {
clearInterval(id);
} else {
width++;
elem.style.left = width + '%';
//console.log(width, elem.style.left, dif);
}
}
}