Skip to content

Instantly share code, notes, and snippets.

@justinwhall
Created January 8, 2013 20:50
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 justinwhall/4487790 to your computer and use it in GitHub Desktop.
Save justinwhall/4487790 to your computer and use it in GitHub Desktop.
jQuery | BG image slider
jQuery(document).ready(function() {
//jQuery('#banner').after('<div id="static-slide"></div>');
var imgArr = new Array('/thedentalsitecontent/themes/176/images/slider-1.png', '/thedentalsitecontent/themes/176/images/slider-2.png', '/thedentalsitecontent/themes/176/images/slider-3.png', '/thedentalsitecontent/themes/176/images/slider-4.png', '/thedentalsitecontent/themes/176/images/slider-5.png', '/thedentalsitecontent/themes/176/images/slider-6.png', '/thedentalsitecontent/themes/176/images/slider-7.png');
var preloadArr = new Array();
var i;
for(i = 0; i < imgArr.length; i++) {
preloadArr[i] = new Image();
preloadArr[i].src = imgArr[i];
}
var currImg = 2;
var time = 4000;
var intID = setInterval(changeImg, time); /* image rotator */
function changeImg() {
jQuery('#banner').animate({
opacity: 0
}, 1000, function() {
jQuery(this).css('background', 'url(' + preloadArr[currImg++ % preloadArr.length].src + ') top left no-repeat');
}).animate({
opacity: 1
}, 1000);
}
jQuery('#banner').hover(function() {
clearInterval(intID);
});
jQuery('#slogan').hover(function() {
clearInterval(intID);
}, function() {
intID = setInterval(changeImg, time);
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment