#box{width: 100px;height: 100px;background: red;position: absolute;left: 0;top: 0;}
js======
function act(obj, attr, target, fn){
clearInterval(obj.timer);
obj.timer = setInterval(function(){
var cur = parseInt(css(obj, attr));
var speed = (target - cur) / 8;
var stop = true;
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
if(target != cur){
stop = false;
}
obj.style[attr] = speed + cur + 'px';
if(stop){
clearInterval(obj.timer);
obj.timer = null;
fn && fn.call(obj);
}
}, 20);
}
var box=document.getElementById('box');
act(box,'top',300);
act(box,'left',300);
为什么我这样调用只执行了第二个函数?