写了一个物体缓冲运动的demo,但是不能到达目标值,求解!
function move(idname, speed, target) {
clearInterval(timer);
var box = document.getElementById(idname);
timer = setInterval(function(){
var v = (target-box.offsetLeft)/speed;
v = v > 0 ? Math.ceil(v):Math.floor(v);
if (parseInt(box.style.left) == target) {
clearInterval(timer);
} else {
box.style.left = box.offsetLeft + v + 'px';
}
}, 30)
}
box.onmouseover = function() {
move('box', 20, 500);
}
为什么是left值是633px?
尚方宝剑之说
相关分类