Skip to content

Instantly share code, notes, and snippets.

@adesignl
Created August 24, 2012 13:46
Show Gist options
  • Save adesignl/3450708 to your computer and use it in GitHub Desktop.
Save adesignl/3450708 to your computer and use it in GitHub Desktop.
A Fading Loop Juery Plugin By: Justin Talant
// Fading Loop Through Items specified in a container
// --------------------------------------------------
// Usage
// $('#tml-container > p').fadeLoop({
// fadeIn: 6000,
// stay: 3000,
// fadeOut: 6000
// });
(function($) {
var default_config = {
fadeIn: 3000,
stay: 3000,
fadeOut: 3000
};
function fade(index, $elements, config) {
$elements.eq(index)
.fadeIn(config.fadeIn)
.delay(config.stay)
.fadeOut(config.fadeOut, function() {
fade((index + 1) % $elements.length, $elements, config);
});
}
$.fn.fadeLoop = function(config) {
fade(0, this, $.extend({}, default_config, config));
return this;
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment