Skip to content

Instantly share code, notes, and snippets.

@Baudin999
Last active December 29, 2015 15:09
Show Gist options
  • Save Baudin999/7688409 to your computer and use it in GitHub Desktop.
Save Baudin999/7688409 to your computer and use it in GitHub Desktop.
jQuery image rotator extension
// a jQuery extension for an image rotator with options
(function ($) {
$.fn.rotate = function (options) {
// initialize the options object if it's null.
var o = options || { images: [] },
that = this,
index = 0,
length = o.images.length;
if (!o.images) o.images = [];
setInterval(function () {
that.attr('src', 'Images/' + o.images[index % length]);
index++;
}, options.waitTime || 1000);};
})(jQuery);
function () {
// call the image rotator
$('#image').rotate({
waitTime: 1500,
images: ["smurf1.jpg", "smurf2.jpg", "smurf3.jpg"]
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment