function animate(obj, target, callback) {
clearInterval(obj.timer);
obj.timer = setInterval(function () {
var step = (target - obj.offsetLeft) / 10;
step = step > 0 ? Math.ceil(step) : Math.floor(step);
if (obj.offsetLeft == target) {
clearInterval(obj.timer);
// 回调函数写到定时器结束里面
/*if (callback) {
// 调用函数
callback();
}*/
callback&&callback();
}
obj.style.left = obj.offsetLeft + step + 'px';
}, 30)
}
前端js缓慢动画
最新推荐文章于 2023-01-06 10:16:05 发布