function nextPage(next=true){
if(moving){
return
}
moving=true;
var currentW= $list.position().left
var offset= next? -IMG_WIDTH:IMG_WIDTH;
if(currentW==0){
currentW=-(listCount-2)*IMG_WIDTH
$list.css("left",currentW)
}else if(currentW==-(listCount-1)*IMG_WIDTH){
currentW=-IMG_WIDTH
$list.css("left",currentW)
}
$list.animate({left:currentW+offset+"px"},"slow",function(){
moving=false
});
updatePoints(next);
} setInterval(function(){
nextPage();
},1000);

解决方案 »

  1.   

    animate 和 setInterval的时间线没有同步,在调用nextPage时,moving还是true就返回了function nextPage(next = true) {
        if (moving) {
            return
        }
        moving = true;
        var currentW = $list.position().left
        var offset = next ? -IMG_WIDTH: IMG_WIDTH;
        if (currentW == 0) {
            currentW = -(listCount - 2) * IMG_WIDTH
            $list.css("left", currentW)
        } else if (currentW == -(listCount - 1) * IMG_WIDTH) {
            currentW = -IMG_WIDTH
            $list.css("left", currentW)
        }
        $list.animate({
            left: currentW + offset + "px"
        }, "slow", function() {
            moving = false;
    setTimeout(function() {
    nextPage();
    }, 400);
        });
        updatePoints(next);
    }setTimeout(function() {
        nextPage();
    }, 1000);