Hay all, i've wrote a simple fading gallery with jQuery. It basically loops though a set of images, fading from one to another. It works perfectly, as predicted, until it gets to the last image, it then doesn't fade from the last to the first, just to displays it.
here's my jQuery
$(document).ready(function(){
Zindex = 99999;
i = 0;
$(".flash img").each(function(){
$(this).css({
'position':'absolute',
'z-index':Zindex,
'display':'none'
});
Zindex--;
});
$(".flash img:first").show();
doFade = function(){
if( i == 6 ) { i = 0; };
$(".flash img:eq("+parseInt(i+1)+")").fadeIn(100);
$(".flash img:eq("+parseInt(i)+")").fadeOut(1000);
setTimeout("doFade()", 2000);
i++;
};
doFade();
});
note: there's only ever going to be 7 images.
And my markup
<div class='flash'>
<img src="img/gallery/picture1.jpg" width="780" height="253" alt="Picture1">
<img src="img/gallery/picture2.jpg" width="780" height="253" alt="Picture2">
<img src="img/gallery/picture3.jpg" width="780" height="253" alt="Picture3">
<img src="img/gallery/picture4.jpg" width="780" height="253" alt="Picture4">
<img src="img/gallery/picture5.jpg" width="780" height="253" alt="Picture5">
<img src="img/gallery/picture6.jpg" width="780" height="253" alt="Picture6">
<img src="img/gallery/picture7.jpg" width="780" height="253" alt="Picture7">
</div>
I think the problem lies in the line
if( i == 6 ) { i = 0; };