2_轮播图.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. * {
  10. margin: 0;
  11. padding: 0;
  12. }
  13. ul {
  14. list-style: none;
  15. }
  16. #container {
  17. width: 590px;
  18. height: 470px;
  19. overflow: hidden;
  20. margin: 100px auto;
  21. position: relative;
  22. }
  23. #img-box {
  24. width: 2950px;
  25. position: absolute;
  26. left: 0;
  27. /* 向左移动 延迟时间 匀速执行 */
  28. transition: left 2s linear;
  29. }
  30. #img-box img {
  31. float: left;
  32. }
  33. #btns {
  34. position: absolute;
  35. right: 10px;
  36. bottom: 10px;
  37. }
  38. #btns li {
  39. width: 20px;
  40. height: 20px;
  41. background: aqua;
  42. color: #eee;
  43. border-radius: 10px;
  44. text-align: center;
  45. line-height: 20px;
  46. float: left;
  47. margin-right: 5px;
  48. }
  49. #btns .select {
  50. background: red;
  51. }
  52. #next,
  53. #prev {
  54. width: 40px;
  55. height: 40px;
  56. position: absolute;
  57. top: 215px;
  58. opacity: 0.4;
  59. display: none;
  60. }
  61. #next {
  62. right: 0;
  63. }
  64. #next span {
  65. font-size: 40px;
  66. }
  67. #prev span {
  68. font-size: 40px;
  69. }
  70. </style>
  71. </head>
  72. <body>
  73. <div id="container">
  74. <div id="img-box">
  75. <img class="selected choice" src="image/1.jpg" alt="">
  76. <img class="selected" src="image/2.jpg" alt="">
  77. <img class="selected" src="image/3.jpg" alt="">
  78. <img class="selected" src="image/4.jpg" alt="">
  79. <img class="selected" src="image/5.jpg" alt="">
  80. </div>
  81. <ul id="btns">
  82. <li class="select">1</li>
  83. <li>2</li>
  84. <li>3</li>
  85. <li>4</li>
  86. <li>5</li>
  87. </ul>
  88. <div id="next">
  89. <span class="iconfont icon-24gl-nextSquare"></span>
  90. </div>
  91. <div id="prev">
  92. <span class="iconfont icon-24gl-previousSquare"></span>
  93. </div>
  94. </div>
  95. <script>
  96. var btn = document.getElementsByTagName('li')
  97. var imgs = document.getElementsByClassName('selected')
  98. var imgBox = document.getElementById('img-box')
  99. for (var i = 0; i < btn.length; i++) {
  100. btn[i].index = i
  101. btn[i].onclick = function () {
  102. for (var j = 0; j < btn.length; j++) {
  103. btn[j].className = ''
  104. }
  105. this.className = 'select'
  106. imgBox.style.left = -590 * this.index + 'px'
  107. }
  108. }
  109. </script>
  110. </body>
  111. </html>