嗨,我只是想知道如何执行带有延迟的for循环

var currentPosition2 = 1;
    for(i=0;i<numberOfSlides;i++) {
        //alert(currentPosition2);
        currentPosition2 = currentPosition2 + 1;
        jQuery('#slideInner').animate({
            'marginLeft' : slideWidth*(-currentPosition2)
        });
    }


目前,所有3张幻灯片同时设置动画,我想在每个循环之间延迟3秒,然后在循环开始之前延迟3秒,

任何帮助,将不胜感激,

谢谢

最佳答案

为我工作:

var numberOfSlides = 5;
function animateSlides(currentPosition2){
    if(currentPosition2 < numberOfSlides){
        alert(currentPosition2);
        currentPosition2 = currentPosition2 + 1;
        var foo = (function(pos){
            return function(){
                animateSlides(pos);
            };
        })(currentPosition2);
        setTimeout(foo, 3000);
    }
}

animateSlides(1);

10-08 08:51