jQuery无缝轮播图

1、无缝轮播图

运行结果图:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <style>
        ul, ol { list-style: none;}
        a {border: none;text-decoration: none;color: inherit;}
        * {margin: 0;padding: 0;}
        .clearfix:after{content: '';display: block;clear: both;}
        .fl-L{ float:left;}
        .fl-R{ float:right;}
​
        body{
            background-color: #cccccc;
        }
​
        #baner{
            position: relative;
            width: 800px;
            height: 450px;
            margin: 100px auto;
            /*box-shadow: 0 0 10px fuchsia;*/
            overflow: hidden;
        }
​
        /* ul */
        #baner #conner .tur{
            position: absolute;
            display: flex;
        }
​
        /* 两边的按钮 */
        #baner #conner .btn img{
            position: absolute;
            cursor: pointer;
        }
        #baner #conner .btn img:hover{
            opacity: 0.6;
        }
        #baner #conner .btn{
            position: absolute;
            width: 800px;
            top: calc(50% - 25px);
        }
        #baner #conner .btn img:nth-child(1){
            left: 10px;
        }
        #baner #conner .btn img:nth-child(2){
            right: 10px;
        }
​
        /* 下面的小圆点 */
        #baner #conner .bum{
            position: absolute;
            /*border: 1px solid red;*/
            bottom: 10px;
            left: calc(50% - 100px);
            width: 200px;
            display: flex;
            justify-content: space-around;
        }
        #baner #conner .bum p{
            text-align: center;
            width: 30px;
            line-height: 30px;
            font-size: 30px;
            font-family: '黑体';
            background-color: #cccccc;
            border-radius: 50%;
            color: white;
            cursor: pointer;
        }
        #baner #conner .bum .on{
            background-color: orangered;
        }
​
    </style>
    <title>Document</title>
    <script src="animate.0.1.3.js"></script>
</head>
<body>
<div id="baner">
    <div id="conner">
        <ul class="tur">
            <li>
                <a href="#"><img src="img/imgs/0.jpg" alt=""></a>
            </li>
            <li>
                <a href="#"><img src="img/imgs/1.jpg" alt=""></a>
            </li>
            <li>
                <a href="#"><img src="img/imgs/2.jpg" alt=""></a>
            </li>
            <li>
                <a href="#"><img src="img/imgs/3.jpg" alt=""></a>
            </li>
            <li>
                <a href="#"><img src="img/imgs/4.jpg" alt=""></a>
            </li>
        </ul>
        <div class="btn">
            <img src="img/imgs/btnL.png" alt="">
            <img src="img/imgs/btnR.png" alt="">
        </div>
        <div class="bum">
            <p class="on">1</p>
            <p>2</p>
            <p>3</p>
            <p>4</p>
            <p>5</p>
        </div>
    </div>
</div>
<script src="js/jquery-1.11.3/jquery.min.js"></script>
<script>
    /*
    $(":animated") ----选中在运动的元素
    is()
     根据选择器、DOM元素或jQuery对象来检测匹配元素集合,如果其中至少有一个元素符号这个给定的表达式就返回true
    列(1):
        is(".c1") 如果匹配到类名c1就返回true,没有匹配到就返回false
    列(2):
        is(":animated") 判断是不是在运动,如果运动是返回true 没有运动就返回false
    */
​
    /* 获取所需元素 */
    var oUl = $("#conner .tur"); //ul
    var aLi = $("#conner .tur li");//li
    var aBtn = $("#conner .btn img");//获取两边的按钮
    var aBum = $("#conner .bum p");//获取小圆点
​
    /* 初始化索引和对象长度 */
    var index = 0;
    var length = aLi.length;
    console.log(length);
​
    /* 克隆第一个元素节点添加到后面 */
    oUl.append(aLi.eq(0).clone());
​
    /* 右边的按钮 */
    aBtn.eq(1).click(function () {
        if(oUl.is($(":animated"))) return;/* 解决动画积累 */
        index++;
        oUl.stop(true).animate({left:-800*index},800,function () {
            if(index >= length){
                index = 0;
                oUl.css({left:0});
            }
        });
        change();
    });
​
    /* 左边的按钮 */
    aBtn.eq(0).click(function () {
        if(oUl.is($(":animated"))) return;/* 解决动画积累 */
        index--;
        if(index < 0){
            index = length-1;
            oUl.css({left:-800*length});
        }
        oUl.stop(true).animate({left:-800*index},800);
        change();
    });
​
    /* 小圆点变色 */
    function change(){
        var n = index;
        if(index === length) n=0;
        aBum.eq(n).addClass("on").siblings().removeClass("on");
    }
​
    /* 小圆点击事件 */
    aBum.click(function () {
        $(this).addClass("on").siblings().removeClass("on");
        index = $(this).index();
        oUl.stop(true).animate({left:-800*index},800);
    });
</script>
</body>
</html>

 

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冒险岛_0_

您的打赏是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值