8e52aed14c7f954dd0ad33d4bda92e6610d80884.svn-base 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. </head>
  7. <style type="text/css">
  8. #banner {
  9. width:100%;
  10. padding:0;
  11. clear: both;
  12. position: relative;
  13. height: 400px;
  14. z-index:1;
  15. }
  16. #img-list {
  17. display: block;
  18. width:5760px;
  19. height: 400px;
  20. overflow: hidden;
  21. z-index:1;
  22. position: relative;
  23. }
  24. #img-list li{
  25. float: left;
  26. width:100%;
  27. height: 400px;
  28. overflow: hidden;
  29. /* position: absolute;
  30. top:0;
  31. left:0; */
  32. z-index: 2;
  33. }
  34. #list {
  35. width:100%;
  36. height:18px;
  37. text-align: center;
  38. position: absolute;
  39. bottom: 10px;
  40. z-index: 100;
  41. }
  42. #list > span {
  43. width:18px;
  44. height: 18px;
  45. overflow: hidden;
  46. display: inline-block;
  47. margin:0 2px;
  48. background: url(../images/yuan.png);
  49. cursor: pointer;
  50. }
  51. #list .on {
  52. background: url(../images/huanyu.png);
  53. }
  54. </style>
  55. <body>
  56. <div id="banner">
  57. <ul id="img-list">
  58. <li><img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fa0.att.hudong.com%2F30%2F29%2F01300000201438121627296084016.jpg&refer=http%3A%2F%2Fa0.att.hudong.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1617503215&t=76c32e76f33522b5103e35ec6bd8ac67" alt="1"/></li>
  59. <li><img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fa2.att.hudong.com%2F27%2F81%2F01200000194677136358818023076.jpg&refer=http%3A%2F%2Fa2.att.hudong.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1617503215&t=4cf2c362ac2d0004c07357751334ad2a" alt="2"/></li>
  60. </ul>
  61. <div id="list">
  62. <span index="1" class="on"></span>
  63. <span index="2"></span>
  64. <span index="3"></span>
  65. </div>
  66. </div>
  67. </body>
  68. <script type="text/javascript">
  69. var banner=document.getElementById('banner');
  70. var imglist=document.getElementById('img-list').getElementsByTagName("li");
  71. var list=document.getElementById('list').getElementsByTagName('span');
  72. var index=0;
  73. var timer=null;
  74. //设置自动播放函数
  75. function autoPlay () {
  76. if (++index >= imglist.length) {index = 0};
  77. changeImg(index);
  78. }
  79. // 鼠标划过整个容器时停止自动播放
  80. banner.onmouseover = function () {
  81. clearInterval(timer);
  82. }
  83. // 鼠标离开整个容器时继续播放至下一张
  84. banner.onmouseout=function(){
  85. timer=setInterval(autoPlay,2000);
  86. }
  87. // 定义并调用自动播放函数
  88. timer = setInterval(autoPlay, 2000);
  89. // 接着定义图片的切换函数
  90. // 定义图片切换函数
  91. function changeImg (curIndex) {
  92. for (var i = 0; i < imglist.length; i++) {
  93. imglist[i].style.display = "none";
  94. list[i].className = "";
  95. }
  96. imglist[curIndex].style.display = "block";
  97. list[curIndex].className = "on";
  98. }
  99. for (var i = 0; i < list.length; i++) {
  100. list[i].index=i;
  101. list[i].onmouseover = function () {
  102. clearInterval(timer);
  103. changeImg(this.index);
  104. };
  105. </script>
  106. </html>