I need to cycle through 4 images on my site, I didn't want to add another plugin to the site, so i created my own simple carousel (html, css, and js below)
My question is, just from looking at this code, is there an obvious simpler/better way to do it?
html:
<section id="carousel">
<img src="images/image_00.jpg" width="202" height="162" />
</section>
css:
#carousel{text-align:center;position:relative;}
#carousel img{top:0;left:0;z-index:1;position:absolute;}
js:
function carousel(el, base_url, images, i){
if (i == images.length ) i = 0;
var el2 = $(el).clone();
$(el).css('z-index', '1');
el2.css('z-index', '0');
el2.attr('src', base_url + images[i]);
$(el).after(el2);
$(el).fadeOut('slow', function(){
$(this).remove();
});
i++;
var func = function(){return carousel(el, base_url, images, i);};
window.timer = setTimeout(func, 4000);
}
$(document).ready(function(){
carousel('#carousel img:first',
'images/',
['image_00.jpg',
'image_01.jpg',
'image_02.jpg',
'image_03.jpg'],
0);
});