function animation(obj, target, callback) {//obj要实现的那个元素, target目标位置 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(); } else { obj.style.left = obj.offsetleft + step + 'px'; } }, 15); }