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.

    $.fn.play = function(){
    var options = $.extend($.fn.qslider.defaultsSetting,$.fn.qslider.options);
    $('.qS-scene').each(function(index){
    $('img', this).delay(options.sceneDuration*index+options.scenePause).each(function(index){
    $(this).delay(options.itemDelay*index).each($.fn.moveIn)
    })
    })
    }

    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: http://wallofscribbles.com/2011/setinterval-the-sneaky-basterd-child-of-javascript/

    # July 3, 2012 at 4:55 pm

    I’d use the setTimeout instead

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

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".