Monday, 18 January 2010

Simple slideshow - with jQuery

// set the current image to 1 - outside of the function
var current = 1;
OW.slideShow = function() {

// each time this function runs, fade out the image
$j(".className img").fadeOut(350,function(){
current++;
if(current==4){current=1;}

// then update the source of the image to the next one
$j(".className img").attr("src","images/content/img-placeholder-"+current+".jpg");

// then fade the image back in again
$j(".className img").fadeIn(350);
});

}

$j(document).ready(function(){

// in the document.read function attach a time onto the function - in this case it'll run every 6 seconds
if($j('.className img').length){var __int = setInterval("OW.slideShow()",6000);}

});

No comments:

Post a Comment