利用fadein、fadeout写轮播
<div id="s" style="width:400px;height:300px;position:relative;"> <div id="s1" style="position:absolute;width:100%;height:100%;background-color:gray;"></div> <div id="s2" style="position:absolute;width:100%;height:100%;background-color:green;"></div> <div id="s3" style="position:absolute;width:100%;height:100%;background-color:blue;"></div> </div>
js:
var count = 1; function huan() { if (count == 4) { count = 1; } $("#s" + count + "").fadeIn(); $("#s" + count + "").siblings().fadeOut(); count++; } setInterval("huan()", 1000);