css样式

    1. *{margin:0;padding:0}
    2. .content{
    3. cursor: pointer;
    4. position: relative;
    5. width:600px;height:400px;
    6. margin-left: auto;margin-right: auto;
    7. border:1px solid #333;
    8. }
    9. #list{
    10. position: absolute;
    11. width:600px;
    12. height:400px;
    13. }
    14. #list img,#prev,#next,#btns{
    15. position: absolute;
    16. }
    17. #list img:not(:first-child){
    18. display: none;
    19. }
    20. #prev,#next{
    21. cursor: pointer;
    22. top:50%;transform: translateY(-50%);
    23. z-index: 100;width:40px;height:70px;
    24. background:url("../images/icon-slides.png");
    25. border:none;
    26. }
    27. #prev{
    28. background-position-x:-86px
    29. }
    30. #prev:hover{
    31. background-position: 0;
    32. }
    33. #next:hover{background-position-x: -43px}
    34. #next{
    35. right:0;
    36. background-position-x:-125px;
    37. }
    38. #btns{z-index: 101;
    39. transform: translateX(-50%);
    40. bottom: 20px;left:50%;}
    41. #btns .current{
    42. background:orangered;
    43. }
    44. #btns>span{
    45. cursor: pointer;
    46. width:20px;
    47. height:20px;
    48. display: inline-block;
    49. border-radius: 50%;
    50. border:1px solid #fff;
    51. background-color:rgba(44,44,44,.3);
    52. }
     <div class="content">
            <div id="list">
                <img src="images/01.png" alt="">
                <img src="images/02.png" alt="">
                <img src="images/03.png" alt="">
                <img src="images/04.png" alt="">
                <img src="images/05.png" alt="">
            </div>
            <button id="prev"></button>
            <button id="next"></button>
            <div id="btns">
                <span class="current"></span>
                <span></span>
                <span></span>
                <span></span>
                <span></span>
            </div>
        </div>
    
     <script>
            var prev=document.getElementById("prev");
            var next=document.getElementById("next");
            var lists=document.querySelectorAll("#list>img");
            var icons=document.querySelectorAll("#btns>span")
            var index=0;  //index  记录下标
            next.onclick=function(){
                index++;
                if(index>4){
                    index=0;
                }
                console.log(index)
                for(let i=0;i<lists.length;i++){        //遍历图片
                    lists[i].style.display="none"       //让所有图片都隐藏
                }
                lists[index].style.display="block"     //只让当前下标下的图片显示
    
                for(let i=0;i<icons.length;i++){       //遍历焦点
                    icons[i].classList.remove("current")   //移去所有焦点
                }
                lists[index].classList.add("current")      //只让当前下标下的焦点增加
            }
            prev.onclick=function(){
                index--;
                if(index<0){
                    index=4;
                }
                for(let i=0;i<lists.length;i++){
                    lists[i].style.display="none";
                }
                lists[index].style.display="block"
    
                for(let i=0;i<icons.length;i++){       
                    icons[i].classList.remove("current")   
                }
                lists[index].classList.add("current")   
            }
            /* 下标重置 */
            for(let i=0;i<icons.length;i++){   //遍历焦点
                icons[i].index=i;
                icons[i].onclick=function(){    //给焦点一个点击事件
                    let currentIndex=this.index;     //指向当前index
    
                    for(let i=0;i<lists.length;i++){
                        lists[i].style.display="none";
                    }
                    lists[currentIndex].style.display="block"
    
                    for(let i=0;i<icons.length;i++){
                        icons[i].classList.remove("current")
                    }
                    icons[currentIndex].classList.add("current")
                }
            }
        </script>