/ Published in: jQuery
Endless loop between 3 images
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$('document').ready(function() { var $imgs = $('#slideshow > img'), current = 0; var nextImage = function() { if (current >= $imgs.length) current = 0; $imgs.eq(current++).fadeIn(function() { $(this).delay(3000).fadeOut(nextImage); }) }; nextImage(); }); HTML <div id="slideshow"> <img src="<?=$this->staticPath?>/img/girl01.jpg"> <img src="<?=$this->staticPath?>/img/girl02.jpg"> <img src="<?=$this->staticPath?>/img/girl03.jpg"> </div> CSS #slideshow img { display: none; }