You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
552 B
16 lines
552 B
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();
|
|
}
|
|
}
|
|
obj.style.left = obj.offsetLeft + step + 'px';
|
|
}, 30);
|
|
} |