Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to put delay after calling javascript functions

I'm using jquery to call some javascript functions with a delay between them.
Also I'm using Jquery Wait

When I call below function,all functions are called recpectively,there are no delays between each other.

$(this)
.call(f1)
.wait(5000)
.call(f2)
.wait(5000)
.call(f3);

Here call function calls some function as I did

$.fn.call = function (f) {
    if (f)
        f();

    return this;
};

What am i doing wrong ? How can i achieve something like this ?
Thank you

like image 474
Myra Avatar asked Jun 07 '26 22:06

Myra


1 Answers

If you want to call a function every 5 seconds use

setTimeout(function(){f1},5000);
setTimeout(function(){f2},10000);
setTimeout(function(){f2},15000);

if you want to call each function 5 seconds after the last one terminated use

setTimeout(function(){f1;setTimeout(function(){f2;setTimeout(function(){f3},5000);},5000);},5000);
like image 55
Thariama Avatar answered Jun 10 '26 12:06

Thariama



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!