これが私のページです。要素の移動をテストするデモですが、いつかページを変更してここに戻った後、DIVがより速く移動するのはなぜですか?
私のcss:
#box1 {
width: 900px;
height: 50px;
background-color: #000;
position: relative;
}
#box2 {
width: 50px;
height: 50px;
background-color: #a00;
position: absolute;
}
私のHTML:
<div id="box1">
<div id="box2"></div>
</div>
私のJs:
var box2 = document.getElementById("box2");
var remove = setInterval(function () {
box2.style.left = "0px";
var move = setInterval(function () {
var newLeft = Math.min(parseInt(box2.style.left) + 5, 850) + "px";
box2.style.left = newLeft;
if (newLeft == "850px") clearInterval(move)
}, 20);
}, 5000)