美文网首页
10.2 简单匀速动画封装

10.2 简单匀速动画封装

作者: 康轩 | 来源:发表于2017-06-01 22:32 被阅读0次

//封装匀速动画框架 可用于无限轮播 如 京东轮播
function constant(obj,speed,target) {//对象,速度,目标值
clearInterval(obj.timer);
obj.timer = setInterval(function () {
var speed1 = target>obj.offsetLeft?speed:-speed;
obj.style.left = obj.offsetLeft+ speed1+'px';
if(Math.abs(target-obj.offsetLeft)<Math.abs(speed1))
{
clearInterval(obj.timer);
obj.style.left = target+'px';
}

},20);

}

相关文章

网友评论

      本文标题:10.2 简单匀速动画封装

      本文链接:https://www.haomeiwen.com/subject/ysgsfxtx.html