基于jQuery的图片广告轮显,带淡入淡出,(注:不用事件绑定的原因是因为绑定后导致时间表紊乱)
var fadetime=1000;
var path=’upload/images/’;
var max=3;
var stop=false;
var tmp=$("#banner a");
function fadeIn () {
if(!stop)
$("#banner a").children("img").fadeTo(fadetime,0.99);
}
function fadeOut () {
if(!stop)
$("#banner a").children("img").fadeTo(fadetime,0.3);
}
function changeImage () {
var images=["1.jpg","2.jpg","3.jpg"];
var urls=["1.jpg","2.jpg","3.jpg"];
if (!stop) {
if($("#focusImage").next().html()!=null){
next=$("#focusImage").next();
}
else{
next=$("#banner ul li:first-child");
}
$("#focusImage").removeAttr("id");
next.attr("id", "focusImage");
}
else{
next=$("#focusImage");
}
$("#banner a").attr("href",urls[parseInt(next.html())-1]);
$("#banner a").children("img").attr("src",path+images[parseInt(next.html())-1]);
if (stop) {
return;
}
else{
setTimeout("fadeOut()", 4000);
setTimeout("changeImage()", 5000);
setTimeout("fadeIn()", 1000);
}
}
function mouse_leave () {
stop=false;
changeImage();
}
function mouse_on (t) {
$("#focusImage").removeAttr("id");
t.id="focusImage";
stop=true;
changeImage();
}
</script>
<div id="banner">
<div style="overflow:hidden; height:0;width:0">
<img src="upload/images/1.jpg" />
<img src="upload/images/2.jpg" />
<img src="upload/images/3.jpg" />
</div>
<a href="#"><img src="" width="870" height="290" /></a>
<ul><li id="focusImage" onmouseover="mouse_on(this);" onmouseout="mouse_leave();">1</li>
<li onmouseover="mouse_on(this);" onmouseout="mouse_leave();">2</li>
<li onmouseover="mouse_on(this);" onmouseout="mouse_leave();">3</li></ul><table class="clear"></table>
</div>