3_轮播图.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 img {
  24. opacity: 0;
  25. position: absolute;
  26. /* 透明度 延迟时间 匀速执行 */
  27. transition: opacity 2s linear;
  28. }
  29. #img-box .choice {
  30. opacity: 1;
  31. }
  32. #btns {
  33. position: absolute;
  34. right: 10px;
  35. bottom: 10px;
  36. }
  37. #btns li {
  38. width: 20px;
  39. height: 20px;
  40. background: aqua;
  41. color: #eee;
  42. border-radius: 10px;
  43. text-align: center;
  44. line-height: 20px;
  45. float: left;
  46. margin-right: 5px;
  47. }
  48. #btns .select {
  49. background: red;
  50. }
  51. #next,
  52. #prev {
  53. width: 40px;
  54. height: 40px;
  55. position: absolute;
  56. top: 215px;
  57. opacity: 0.4;
  58. display: none;
  59. }
  60. #next {
  61. right: 0;
  62. }
  63. #next span {
  64. font-size: 40px;
  65. }
  66. #prev span {
  67. font-size: 40px;
  68. }
  69. </style>
  70. </head>
  71. <body>
  72. <div id="container">
  73. <div id="img-box">
  74. <img class="selected choice" src="image/1.jpg" alt="">
  75. <img class="selected" src="image/2.jpg" alt="">
  76. <img class="selected" src="image/3.jpg" alt="">
  77. <img class="selected" src="image/4.jpg" alt="">
  78. <img class="selected" src="image/5.jpg" alt="">
  79. </div>
  80. <ul id="btns">
  81. <li class="select">1</li>
  82. <li>2</li>
  83. <li>3</li>
  84. <li>4</li>
  85. <li>5</li>
  86. </ul>
  87. <div id="next">
  88. <span class="iconfont icon-24gl-nextSquare"></span>
  89. </div>
  90. <div id="prev">
  91. <span class="iconfont icon-24gl-previousSquare"></span>
  92. </div>
  93. </div>
  94. <script>
  95. var btn = document.getElementsByTagName('li')
  96. var img = document.getElementsByClassName('selected')
  97. for (var i = 0; i < btn.length; i++) {
  98. btn[i].index = i
  99. btn[i].onclick = function () {
  100. for (var j = 0; j < btn.length; j++) {
  101. btn[j].className = ''
  102. img[j].className = 'selected'
  103. }
  104. this.className = 'select'
  105. img[this.index].className = 'selected choice'
  106. }
  107. }
  108. </script>
  109. </body>
  110. </html>