JS实现轮播图的动画效果函数封装
作者:互联网
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);
callback && callback();
}
obj.style.left = obj.offsetLeft + step + 'px';
}, 15);
}
标签:obj,轮播,timer,JS,callback,step,offsetLeft,封装,target 来源: https://blog.csdn.net/xiaoxiao_654/article/details/116051261