bAN
bAN

Reputation: 13835

Repeat effect with timing

I have this code

$(document).ready(function () {
    $('.HighlightedTr').delay(1000).effect("highlight", {}, 1000);        
});`

Works good but once.. Is it possible to repeat this with some delay? like every seconds or every 5 seconds?

Txs

Upvotes: 1

Views: 2270

Answers (3)

genesis
genesis

Reputation: 50982

$(document).ready(function () {
    setInterval(function(){
          $('.HighlightedTr').delay(1000).effect("highlight", {}, 1000);
    }, 5000);
});

Upvotes: 2

ThiefMaster
ThiefMaster

Reputation: 318628

$(document).ready(function () {
    window.setInterval(function() {
        $('.HighlightedTr').delay(1000).effect("highlight", {}, 1000);        
    }, 5000);
});

repeats it evers 5 seconds.

Upvotes: 2

Alessandro Vendruscolo
Alessandro Vendruscolo

Reputation: 14875

Yes, use the setInterval function.

var interval = setInterval(code, 4000);

This will execute code every 4000 milliseconds.

Code could also be an anonymous function.

var interval = setInterval(function() {
        ....
    }, 4000);

setTimeout instead executes your code just once, after some time.

var timeout = setTimeout(function() {
        ...
    }, 4000);

You code will be called after 4000 milliseconds.

Finally, you can cancel these timers with clearTimeout(interval).

Upvotes: 2

Related Questions