On page load I setup some functions and call the first one which is supposed to go through step by step.
after5Seconds();
function after5Seconds() {
setTimeout(hideOne, 5000);
}
function hideOne() {
$('.toggleme#one').fadeOut(showTwo);
}
function showTwo() {
$('.toggleme#two').fadeIn('125', 'swing', startAllOver);
}
I'm finding that often some callbacks get stalled and fail silently and i'm starting to update each to be more like:
- setTimeout to trigger the callback in N milliseconds if it hasn't already been triggered
Something like:
function wrapMeInDelay(fn, timer) {
var hasBeenCalled = false;
var ctx = function() {
if (hasBeenCalled) {
return false;
} else {
hasBeenCalled = true;
return fn();
}
};
setTimeout(ctx, timer);
return ctx;
}
basically I want to start adding timeouts to the callbacks to make sure they are called if the jquery/whatever callback doesn't trigger it first.
Is there another more common way of doing this i'm not aware of?