jq轮播图

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>轮番图</title>
    <style>
        *{
            padding:0;
            margin:0;
        }
        .box{
            width:700px;
            height:500px;
            margin:80px auto;
            border:1px solid red;
            position: relative;
        }
        ul{
            list-style: none;
        }
        div ul.pic li img{
            width:700px;
            height: 500px;


        }
        .box ul.pic li{
            position:absolute;
            display: none;

        }
        div.box ul.point {
            width:135px;  /*15*5+10*5+1*10*/
            height:22px;
            position: absolute;
            left:50%;
            bottom:20px;
            margin-left:-72px;

        }
        div ul.point li{
            width:15px;
            height:15px;
            border-radius: 50%;
            border:1px solid purple;
            float:left;
            margin:5px;
        }
        .left{
            position:absolute;
            left:0;
            top:50%;
        }
        .right{
            position:absolute;
            right:0;
            top:50%;
        }
        .box .ear li{
            width:30px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            font-size: 18px;
            font-weight: bold;
            margin-top:-15px;
            position:absolute;
        }
        /*.box .pic li.show{*/
            /*display:block;}*/

        .point li.shows{
            background-color: red;

        }
    </style>

</head>
<body>
<div class="box">
    <ul class="pic">
    <li ><img src="http://img.ivsky.com/img/bizhi/pre/201512/20/huge-005.jpg" ></li>
    <li ><img src="http://img.ivsky.com/img/bizhi/pre/201512/20/huge.jpg"></li>
    <li ><img src="http://img.ivsky.com/img/bizhi/pre/201512/20/huge-001.jpg"></li>
    <li ><img src="http://img.ivsky.com/img/bizhi/pre/201512/20/huge-002.jpg"></li>
    <li ><img src="http://img.ivsky.com/img/bizhi/pre/201512/20/huge-004.jpg"></li>
    </ul>
    <ul class="point">
        <li ></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>
    <ul class="ear">
        <li class="left">&lt</li>
        <li class="right">&gt</li>

    </ul>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
    <script>
        var $opoi = $("div ul.point li");  //五个圆圈
        var $opic = $("div.box ul.pic li");  //五张图
        var $btn = $("div ul.ear li");  //两个小耳朵
        var len = $opic.length;
        // alert(len);
        var first = 0;
        $opic.eq(first).show();
        $opoi.eq(first).addClass("shows");


        $opoi.on("click",function(){   //控制小圆圈
            var i = $(this).index();
            if (i !== first){
                change(i);
            }

        });
        $btn.on("click",function () {  //控制左右两个小耳朵
            var i = first;
            if($(this).index() == 0){
                i--;
                i %= len;
            }
            else{
                i++;
                i %= len;
            }
            change(i);
        });
        function change(i) {
            $opic.eq(first).fadeOut(500);
            $opoi.eq(first).removeClass("shows");
            first = i;
            $opic.eq(i).fadeIn(500);
            $opoi.eq(i).addClass("shows");
        }
        timer = setInterval(function () {  //设置定时器
            $opic.eq(first).fadeOut(500);
            $opoi.eq(first).removeClass("shows");
            var i = (first+1)%len;
            first = i;
            $opic.eq(i).fadeIn(500);
            $opoi.eq(i).addClass("shows");
        },1000)


        
    
    </script>
</div>


</body>
</html>

posted @ 2018-11-24 21:50  龙~白  阅读(132)  评论(0编辑  收藏  举报