我需要在我的网站上循环浏览4个图像,我不想在网站上添加另一个插件,所以我创建了自己的简单传送带(html,css和js)优化一个简单的jQuery图像传送带
我的问题是,仅仅从看这段代码,有没有一种明显更简单/更好的方法来做到这一点?
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);
});
为什么不使用CSS图像的宽度和高度? – 2010-08-21 10:28:33
它只是一个复制粘贴。 无关 – Tombigel 2010-08-21 11:48:02