首页 > 代码库 > 图片轮播

图片轮播

<div id="wai">
   <div id="wai_a1">
     <img class="img" src="http://www.mamicode.com/图片/张掖丹霞7.jpeg" width="640px" height="400px" />
       <img class="img" src="http://www.mamicode.com/图片/丹霞1.jpg" width="640px" height="400px" /> 
       <img class="img" src="http://www.mamicode.com/图片/丹霞4.jpg" width="640px" height="400px" />
       
  </div>
   <div id="wai_a2">
   
      <div class="wai_a2_a">
      <img src="http://www.mamicode.com/图片/张掖丹霞3.jpeg" width="360px" height="200px"/>
      </div>
      <div class="wai_a2_a">
      <img src="http://www.mamicode.com/图片/丹霞3.jpg" width="360px" height="200px" />
      </div>
   
   
  </div>

</div>

  

var index=0;
var img=document.getElementsByClassName("img");
huan();
function huan(){
    //xianshi();
    for(var i=0;i<img.length;i++){
        img[i].style.display="none";
        }
    img[index].style.display="block";
    if(index>=img.length-1){
        index=0;
        }
    else{
        index++;
        }
    window.setTimeout("huan()",2000);
}
/*function xianshi(){
    for(var i=0;i<img.length;i++){
        img[i].style.display="none";
        }
    img[index].style.display="block";    
    }*/

 

图片轮播