无自动播放效果

css

  1. <style>
  2. *{
  3. margin: 0;
  4. padding: 0;
  5. }
  6. li{
  7. list-style: none;
  8. }
  9. .box{
  10. width: 600px;
  11. height: 400px;
  12. margin: 0 auto;
  13. position: relative;
  14. overflow: hidden;
  15. }
  16. ul{
  17. float: left;
  18. width: 600%;
  19. height:400px;
  20. }
  21. ul>li{
  22. float: left;
  23. display: none;
  24. }
  25. ol{
  26. position: absolute;
  27. bottom:20px;
  28. right: 50%;
  29. transform: translateX(50%);
  30. }
  31. ol>li{
  32. display: inline-block;
  33. cursor: pointer;
  34. width: 20px;
  35. height: 20px;
  36. border-radius: 50%;
  37. background-color: rgba(44,44,44,.3);
  38. border: 1px solid #fff;
  39. }
  40. #arrow_l,#arrow_r{
  41. position: absolute;
  42. cursor: pointer;
  43. top: 50%;
  44. transform: translateY(-50%);
  45. z-index: 100;
  46. width: 40px;
  47. height: 70px;
  48. background: url(./images/icon-slides.png);
  49. border: none;
  50. }
  51. #arrow_l{
  52. background-position-x: -86px;
  53. }
  54. #arrow_r{
  55. right: 0;
  56. background-position-x: -125px;
  57. }
  58. .current{
  59. background-color: #ff4500;
  60. }
  61. </style>

html

  1. <div class="box">
  2. <button id="arrow_l"></button>
  3. <button id="arrow_r"></button>
  4. <ul>
  5. <li style="display: block;"><img src="./images/01.png" alt=""></li>
  6. <li><img src="./images/02.png" alt=""></li>
  7. <li><img src="./images/03.png" alt=""></li>
  8. <li><img src="./images/04.png" alt=""></li>
  9. <li><img src="./images/05.png" alt=""></li>
  10. </ul>
  11. <ol class="circle">
  12. <li class="current"></li>
  13. <li></li>
  14. <li></li>
  15. <li></li>
  16. <li></li>
  17. </ol>
  18. </div>

js

  1. <script>
  2. var list=document.querySelectorAll("ul>li");
  3. var ol=document.querySelectorAll("ol>li");
  4. var arrow_l=document.querySelector("#arrow_l");
  5. var arrow_r=document.querySelector("#arrow_r");
  6. var count=0;
  7. function remove(){
  8. for(var i=0;i<list.length;i++){
  9. list[i].style.display="none";
  10. }
  11. for(var i=0;i<ol.length;i++){
  12. ol[i].className="";
  13. }
  14. }
  15. function add(){
  16. remove();
  17. list[count].style.display="block";
  18. ol[count].className="cureent";
  19. }
  20. function towards(){
  21. if(count==list.length-1){
  22. count=0
  23. }else{
  24. count++;
  25. }
  26. add();
  27. }
  28. function aleft(){
  29. if(count==0){
  30. count=list.length-1;
  31. }else{
  32. count--;
  33. }
  34. add();
  35. }
  36. arrow_r.onclick=function(){
  37. towards();
  38. }
  39. arrow_l.onclick=function(){
  40. towards();
  41. }
  42. for(var i=0;i<ol.length;i++){
  43. ol[i].setAttribute('index',i);
  44. ol[i].onclick=function(){
  45. aleft();
  46. }
  47. }
  48. </script>