为什么要在animate()函数中加if(offset==0)这个判断条件呢?
function animate(offset){
animated = true;
if(offset == 0){
return;
}
var left = parseInt(list.style.left) + offset;
var time = 300; //位移总时间
var interval = 10; //位移间隔时间
var speed = offset/(time/interval); //每次位移量
function go(){
if((speed < 0 && parseInt(list.style.left) > left) || (speed > 0 && parseInt(list.style.left) < left)){
list.style.left = parseInt(list.style.left) + speed + 'px';
setTimeout(go,interval);
}else{
list.style.left = left + 'px';
if(left > -600){
list.style.left = -3000 + 'px';
}
if(left < -3000){
list.style.left = -600 + 'px';
}
animated = false;
}
}
go();
}