实例
<!DOCTYPE html> <html> <head> <title>轮播图</title> <meta charset="utf-8"> <style type="text/css"> *{margin:0;padding:0;} .main{ width:800px; height:1200px; margin:20px auto; background: #ccc; } .pic{ width: 500px; height:300px; margin:0 auto; overflow: hidden; position: relative; } .pic img{ width: 500px; height:300px; } .pic_span{ position:absolute;bottom:0;left:0; width: 500px; text-align: center; } .pic span{ color:#fff; display: inline-block; cursor:pointer; z-index: 999; } </style> </head> <body> <div class="main"> <div class="pic"> <a href="" target="_blank"><img src="static/images/1.jpg"></a> <a href="" target="_blank"><img src="static/images/2.jpg"></a> <a href="" target="_blank"><img src="static/images/3.jpg"></a> <a href="" target="_blank"><img src="static/images/4.jpg"></a> <a href="" target="_blank"><img src="static/images/5.jpg"></a> <div class="pic_span"> <span onclick="wheel(0)">1</span> <span onclick="wheel(1)">2</span> <span onclick="wheel(2)">3</span> <span onclick="wheel(3)">4</span> <span onclick="wheel(4)">5</span> </div> </div> </div> <script type="text/javascript"> function wheel(num){ var pic_a=document.getElementsByClassName('pic')[0].getElementsByTagName('a'); for(i=0;i<pic_a.length;i++){ pic_a[i].style.display="none"; }//for循环用来遍历出所有的a标签,并且将它们全部隐藏 pic_a[num].style.display="block";//点击时,使对应的a元素显示,num的值是就是a元素下标的值 } </script> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例