<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <style type="text/css"> *{ margin:0px auto; padding:0px} #tp{ width:100%; height:350px} .img{ display:none} #dian{ width:200px; height:15px; position:relative; top:-25px} .yuan{ width:13px; height:13px; float:left; margin-left:20px; border:2px solid #FFF;border-radius:100px; background-color:#FFF} .yuan:hover{ cursor:pointer} </style> </head> <body> <div id="tp"> <img style="display:block" class="img" src="img/1e30e924b899a9015ffb691a1e950a7b0308f5cb.jpg" width="1000" height="350" /> <img class="img" src="img/0c7abcfc2ba612631d883b6171dcc774.jpg" width="1000" height="350" /> <img class="img" src="img/969c65ce130ccd17c93a8a6bf2d9fd7c.jpg" width="1000" height="350" /> <img class="img" src="img/ee797172eb553662868372d70f81dac0.jpg" width="1000" height="350" /> <img class="img" src="img/benbenla-08c.jpg" width="1000" height="350" /> </div> <div id="dian"> <div bs="0" class="yuan" οnclick="xianshi(this,'0')"></div> <div bs="1" class="yuan" οnclick="xianshi(this,'1')"></div> <div bs="2" class="yuan" οnclick="xianshi(this,'2')"></div> <div bs="3" class="yuan" οnclick="xianshi(this,'3')"></div> <div bs="4" class="yuan" οnclick="xianshi(this,'4')"></div> </div> <script type="text/javascript"> //图片索引 var sy = 0; //间隔调用 window.setInterval("Huan()",3000); //调一下换一个 function Huan() { var img = document.getElementsByClassName("img"); sy++; //索引加1 //判断是否到了最后一张 if(sy>=img.length) { sy=0; } //让所有隐藏 for(var i=0;i<img.length;i++) { img[i].style.display="none"; } //让下一张显示 img[sy].style.display="block"; //换圆点的样式 var yuan = document.getElementsByClassName("yuan"); for(var j=0;j<yuan.length;j++) { if(yuan[j].getAttribute("bs")==sy) { yuan[j].style.backgroundColor = "gray"; } else { yuan[j].style.backgroundColor = "white"; } } } function xianshi(t,s) { sy=s; var img = document.getElementsByClassName("img"); //让所有隐藏 for(var i=0;i<img.length;i++) { img[i].style.display="none"; } //让下一张显示 img[s].style.display="block"; //改自身样式 var yuan = document.getElementsByClassName("yuan"); for(var j=0;j<yuan.length;j++) { yuan[j].style.backgroundColor="white"; } t.style.backgroundColor="gray"; } </script> </body> </html>
结果参考