封装函数匀速运动 stattMove
function startMove(dom, target) {
clearInterval(timer);
var iSpeed = target - dom.offsetLeft > 0 ? 7 : -7,
timer;
timer = setInterval(function () {
if (Math.abs(target - dom.offsetLeft) < Math.abs(iSpeed) ) {
clearInterval(timer);
dom.style.left = target + "px"
}else{
dom.style.left = dom.offsetLeft + iSpeed + "px";
};
}, 30);
}
JavaScript运动
最新推荐文章于 2020-02-22 19:09:09 发布