Treehouse: Grow your CSS skills. Land your dream job.

jQuery run function in a loop?

  • # July 3, 2012 at 4:40 pm

    Hi i’m wondering how to run a function repetedly for an infinite ammount of time, basically i’m trying to achieve “autoplay” with this function.

    $ = function(){
    var options = $.extend($.fn.qslider.defaultsSetting,$.fn.qslider.options);
    $('img', this).delay(options.sceneDuration*index+options.scenePause).each(function(index){

    I could make a separate function if it helps, if you want to see it in action (i’m not good @ describing) go here:

    # July 3, 2012 at 4:52 pm

    You could use setInterval, but I’m sure some smarter people would explain to you why it’s not good and there’s something better.

    Here’s some more reading on it:

    # July 3, 2012 at 4:55 pm

    I’d use the setTimeout instead

    function yourFunction() {
    // content of yourFunction
    setTimeout("yourFunction()", speed);
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.