Skip to content

Instantly share code, notes, and snippets.

@Lasha
Created January 11, 2013 14:26
Show Gist options
  • Save Lasha/4511021 to your computer and use it in GitHub Desktop.
Save Lasha/4511021 to your computer and use it in GitHub Desktop.
Self invoking function after initial trigger, utilizing setTimeouts
var activeCounter = 0,
$acitivityMsgs = $('.progress-bar').find('.message'),
$activeMsg = $acitivityMsgs.filter('.active'),
totalMessages = $acitivityMsgs.length,
activityTimer = 5000;
function activityAdvance(){
if (activeCounter < totalMessages-1){
$activeMsg = $activeMsg.fadeOut('slow').removeClass('active').next().fadeIn('fast').addClass('active');
// activeCounter = $activeMsg.index('.message') + 1;
activeCounter += 1;
var timeout = setTimeout(function(){ activityAdvance(); clearTimeout(timeout); }, activityTimer);
} else {
$activeMsg.fadeOut('slow').removeClass('active')
$activeMsg = $acitivityMsgs.eq(0).fadeIn('fast').addClass('active');
activeCounter = 0;
var timeout = setTimeout(function(){ activityAdvance(); clearTimeout(timeout); }, activityTimer);
}
}
setTimeout(function(){
activityAdvance();
},activityTimer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment