+ 1
Why is javascript animation not working properly with the DOM?
when you use animation with other logics, it doesn't work fine with the DOM objects.
4 odpowiedzi
+ 7
You will need a little bit of css for positioning the box. You need to set its position relative.
https://code.sololearn.com/Wlh16tR39VnR/?ref=app
+ 4
With other logics : I am unable to understand this. Can u share the code in which u have problem ??
0
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<div id="container">
<div id="box"> </div>
</div>
<script>
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';
}
}
};
</script>
</body>
</html>
0
am trying to make the box move left, right, up and down the container but it refuse