There is no end to JavaScript image sliders. Rather than using one which probably had a lot of bells and whistles that I wasn’t going to use (and may have taken me just as long to rewrite the client’s markup), I just created one from scratch. The snippet of code below uses jQuery and the preLoadImages plugin.
Show the code
<script type="text/javascript">
//List the images in the slides var as an array
slides = ['1.jpg','2.JPG','new.JPG'];
//Preload the slides, original plugin found at: http://plugins.jquery.com/project/preloadImages
$.preLoadImages(slides);
var changeSlides = ({
// Set some initial values
interval: 8000,
refreshSlides: true,
slideNum: 0,
do: function (event) {
// Function to change slides either on interval or on click
// sni = slide number indicator (clickable numbers to change slides manually)
if (event) {
event.preventDefault();
if (event.originalEvent) this.refreshSlides = false;
obj = event.target;
if (intID) clearInterval(intID);
}
else {
slideNum++;
obj = '#sni_'+(this.slideNum+1);
if ($(obj).length == 0) {obj = '#sni_1';slideNum = 0;}
}
$('#mainslide_2').children('a').attr('href',$(obj).attr('href'));
pos = $(obj).attr('id').replace('sni_','')-1;
$('#mainslide_2 img').css("display","none").attr('src',slides[pos]).fadeIn();
$('.slidebar a').removeClass('selectedSlide');
$(obj).addClass('selectedSlide');
return false;
},
init: function () {
$(function () {
$('.slidebar a:eq(0)').addClass('selectedSlide');
//Setup interval for changing slides
intID = setInterval(function () {changeSlides.do();},changeSlides.interval);
//Attach changeSlides function to click event for slide chooser numbers
$('.slidebar a').click(function (event) {changeSlides.do(event);});
});
}
});
changeSlides.init();
</script>