简单的轮播图

简单的轮播图

这是一种超级简单的轮播图 可以供新手参考 主要是通过数组覆盖img的src

CSS部分

 <style>
        * {
            margin: 0;
            padding: 0;
        }

        a {
            text-decoration: none;
            display: block;
        }

        #imgs {
            margin: 50px auto;
            height: 300px;
            width: 600px;
            border: 1px solid orange;
            position: relative;
        }

        ul,
        li {
            list-style: none;
        }

        ul {

            position: absolute;
            bottom: 8px;
            right: 10px;
        }

        li {
            float: left;
            margin-left: 2px;
            width: 10px;
            height: 25px;
            border: 1px solid orange;
        }

        a img {
            height: 300px;
            width: 600px;
        }
        span,a{
            width: 50px;
            height: 50px;
            background-color:red;
            text-align: center;
            line-height: 50px;
        }
        span{
            position:absolute;
            top: 50%;
            transform: translateY(-50%);
        
        }
        span a:hover{
            background-color:rgba(255,255,255,0.5);
        }
        .left{
            left: 0;
        }
        .right{
            right: 0;
        }
    </style>
```css

```html
 <div id="imgs">
        <a href="javascript:;"><img src="../img/1.jpg" alt=""></a>
        <ul>
            <li style="background-color:orange"></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
        <span class="left"><a href="javascript:;"><</a></span>
        <span class="right"><a href="javascript:;">></a></span>
    </div>

`<script src="../JS/jquery.min.js"></script>
    <script>
        let index = 0;
        const arr=["../img/1.jpg","../img/2.jpg","../img/3.jpg","../img/4.jpg","../img/5.jpg"];
        t=setInterval(fun1,1500);
        $("#imgs").mouseenter(function() {
            clearInterval(t);
        })
        $("#imgs").mouseleave(function() {
            t=setInterval(fun1,1500);
        })
        function fun1() {
            index++;
            if (index == 5) {
                index = 0;
            }
            let path = arr[index];
            $("#imgs img").attr("src",path);
            $("ul li").eq(index).css("background","orange").siblings("li").css("background","");
        }
        $("ul li").mouseenter(function() {
            clearInterval(t);
            let index = $(this).index();
            let path = arr[index];
            $("#imgs img").attr("src",path);
            $(this).css("background","orange").siblings("li").css("background","");
        })
        $('.right').click(function() {
            fun1();
        })
        $(".left").click(function() {
            if (index==0) {
                index=5
            }
            index--;
            let path = arr[index];
            $("#imgs img").attr("src",path);
            $("ul li").eq(index).css("background","orange").siblings("li").css("background","");
        })
    </script>``

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值