-1

我尝试过 for 循环等,但我无法运行此函数两​​次

            function play() {
                setInterval(function(){
                    var next = $(".furniture .active, .pets .active").next("img");
                    var i = 0;
                    var current = next.prev("img");
                    current.removeClass("active").addClass("current")
                    next.removeClass("current").addClass("active");
                    if (!next.length) {
                        next = $(".furniture img:first");
                        };
                    }
                }, 3000);
            }   
            play();
4

2 回答 2

4

你可能想要这样的东西:

function play(timeout) { 
  setTimeout(function() {
    ...
  }, timeout);
}
play(3000);
play(6000);
于 2013-11-05T19:25:15.790 回答
1
var counter = 0;

play();

function play()
{
    counter = counter + 1;

    var next = $(".furniture .active, .pets .active").next("img");
                    var i = 0;
                    var current = next.prev("img");
                    current.removeClass("active").addClass("current")
                    next.removeClass("current").addClass("active");
                    if (!next.length) {
                        next = $(".furniture img:first");
                        };
                    }

    if (counter < 2)
    {        
        setTimeout(play(), 3000);
    }
}
于 2013-11-05T19:41:11.467 回答