<html> <head> <title>瞎写的图片淡入幻灯片效果</title><style> * {margin:0;padding:0;} .wrap {overflow:hidden;zoom:1;position:relative;width:350px;background:#fff;} ul,dl {margin:0;padding:0;list-style:none;} ul {position:absolute;bottom:5px;right:5px;} ul li {width:20px;height:20px;border:1px solid #bbb;float:left;line-height:20px;text-align:center;cursor:pointer;background:#eee;border-bottom:1px solid #bbb;margin-right:1px;} ul .active {background:#fff;color:#fff;font-size:16px;font-weight:bold;background:#333;border:1px solid #aaa;} dl dd {display:none;height:111px;background:#fff;border:1px solid #aaa;text-align:center;line-height:111px;font-size:50px;font-family:arial;} dl dd img {width:348px;height:111px;display:block;} </style> <script> function imgbox(wra,tab,con){ var oDiv=document.getElementById(wra); var aBtn=document.getElementById(tab).getElementsByTagName('li'); var aDiv=document.getElementById(con).getElementsByTagName('dd'); var i=0; var iNow=0; var timer=null; var timer2=null; var al=1; function dr(){ aDiv[iNow].style.filter="alpha(opacity="+al+')'; aDiv[iNow].style.opacity=al/100; if(al<100){ al+=2; } }function move(){ for(i=0;i<aBtn.length;i++){ aDiv[i].style.display='none'; aBtn[i].className=''; clearInterval(timer2); al=0; } aBtn[iNow].className='active'; aDiv[iNow].style.display='block'; timer2=setInterval(dr,10) } for (i=0;i<aBtn.length;i++){ aBtn[i].index=i; aBtn[i].onclick=function (){ iNow=this.index; move(); } } timer=setInterval(function(){ iNow++; if(iNow>=aBtn.length){ iNow=0; } move(); },3000) oDiv.onmouseover=function(){ clearInterval(timer); } oDiv.onmouseout=function(){ timer=setInterval(function(){ iNow++; if(iNow>=aBtn.length){ iNow=0; } move(); },3000) } } window.onload=function(){ imgbox ('b1','tabb','conn'); } </script> </head> <body> <div id="b1" class="wrap"> <ul id="tabb"> <li class="active">1</li> <li>2</li> <li>3</li> </ul> <dl id="conn"> <dd style="filter:alpha(opacity=100);opacity=1;display:block;background:red"><img src=http://www.cwydesign.com/effects/UploadFiles_7074/201008/2010081122582652.jpg /></dd> <dd style="background:blue"><img src=http://www.cwydesign.com/effects/UploadFiles_7074/201008/2010081122582644.jpg /></dd> <dd style="background:green"><img src=http://www.cwydesign.com/effects/UploadFiles_7074/201008/2010081122582622.jpg /></dd> </dl> </div> </body> </html> |