Last active
December 29, 2015 15:09
-
-
Save Baudin999/7688409 to your computer and use it in GitHub Desktop.
jQuery image rotator extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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