I have about 3 JavaScript timers working at the same time on a page using settimeout
,开发者_如何学Go but the functions called by these timers are not working smoothly and it seems that the timers are waiting on each other, and some times hang the page.
Is there a best practice when dealing with js timers to avoid this behavior?
Examples:
Sometimes use jQuery timers like this:
$(document).everyTime(1000, "blinkRed", function (i) {
$(price).toggleClass('valuered');
}, 10);
and sometimes I use the normal settimeout
JavaScript function.
The timers are not waiting for each other, but the functions that are called when the timer is done, are. So, when you put blocking code (like an alert) in the first timer function, it will prevent the other timers to go off.
精彩评论