3_淡入淡出轮播图.html 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. margin: 100px auto;
  20. position: relative;
  21. }
  22. #img-box img{
  23. position: absolute;
  24. opacity: 0;
  25. transition: opacity 1s linear;
  26. }
  27. #img-box .choice{
  28. opacity: 1;
  29. }
  30. #btns{
  31. position: absolute;
  32. right: 10px;
  33. bottom: 10px;
  34. }
  35. #btns li{
  36. width: 20px;
  37. height: 20px;
  38. background: aqua;
  39. color: white;
  40. text-align: center;
  41. line-height: 20px;
  42. border-radius: 10px;
  43. float: left;
  44. margin-right: 5px;
  45. }
  46. #btns .select{
  47. background: red;
  48. }
  49. </style>
  50. </head>
  51. <body>
  52. <div id="container">
  53. <div id="img-box">
  54. <img class="selected choice" src="image/1.jpg" alt="">
  55. <img class="selected" src="image/2.jpg" alt="">
  56. <img class="selected" src="image/3.jpg" alt="">
  57. <img class="selected" src="image/4.jpg" alt="">
  58. <img class="selected" src="image/5.jpg" alt="">
  59. </div>
  60. <ul id="btns">
  61. <li class="select">1</li>
  62. <li>2</li>
  63. <li>3</li>
  64. <li>4</li>
  65. <li>5</li>
  66. </ul>
  67. <div id="next">
  68. <span class="iconfont icon-next"></span>
  69. </div>
  70. <div id="prev">
  71. <span class="iconfont icon-prev"></span>
  72. </div>
  73. </div>
  74. <script>
  75. var btn = document.getElementsByTagName('li')
  76. var img = document.getElementsByClassName('selected')
  77. for(var i=0;i<btn.length;i++){
  78. btn[i].index = i
  79. btn[i].onclick = function(){
  80. for(var j=0;j<btn.length;j++){
  81. btn[j].className = ''
  82. img[j].className = 'selected'
  83. }
  84. this.className = 'select'
  85. img[this.index].className = 'selected choice'
  86. }
  87. }
  88. </script>
  89. </body>
  90. </html>