Skip to content

Instantly share code, notes, and snippets.

@stephband
Created August 6, 2012 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephband/3273140 to your computer and use it in GitHub Desktop.
Save stephband/3273140 to your computer and use it in GitHub Desktop.
Automatic slides cycling for Bolt
(function(jQuery, undefined){
// Cycle news slides
jQuery(document).ready(function(){
var slides = jQuery('.header_slide'),
length = slides.length,
i = slides.index(slides.filter('.active')[0]),
durationShort = 8000,
durationLong = 48000,
timer, fn;
function activateItem(i) {
slides.eq(i).trigger('activate');
}
function activate() {
fn((i+1)%length);
}
function clearTimer() {
clearTimeout(timer);
timer = null;
}
slides
.bind('activate', function(e) {
// Keep index up to date.
i = slides.index(this);
clearTimer();
// Use e.relatedTarget to determine if this activate is the result
// of a user action or not. If it is, the slide pauses longer.
timer = setTimeout(activate, e.relatedTarget ? durationLong : durationShort);
})
.hover(function(e) {
fn = clearTimer;
}, function() {
fn = activateItem;
// If the timer has stopped, kick it off again
if (!timer) { activate(); }
});
// Set the ball rolling
fn = activateItem;
timer = setTimeout(activate, durationShort);
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment