h5轮播图 自动轮播

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>轮播</title>
    <script src="js/jquery-1.8.3.min.js"></script>
    <script src="js/lunbo.js"></script>
    <link rel="stylesheet" href="css/lunbo.css" />
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    .lunbo {
        padding: 0px 10px;
        margin-top: 20px;
    }

    .wrap {
        width: 100%;
        height: 100px;
        overflow: hidden;
        position: relative;
        box-shadow: 2px 2px 2px #666;
    }

    .wraps {
        width: 100%;
        height: 100px;
    }

    .wraps img {
        float: left;
        cursor: pointer;
        position: absolute;
        top: 0;
        left: 0;
    }

    .page {
        width: 100%;
        position: absolute;
        bottom: 10px;
        text-align: center;
    }

    .page span {
        display: inline-block;
        width: 10px;
        height: 5px;
        text-align: center;
        line-height: 20px;
        background: rgba(0, 0, 0, 0.5);
        color: #fff;
        margin-left: 10px;
        cursor: pointer;
    }

    .page span.current {
        background: #ffffff;
    }

    .btnBox span {
        width: 30px;
        height: 30px;
        display: inline-block;
        background: rgba(0, 0, 0, 0.5);
        color: #fff;
        font-size: 20px;
        text-align: center;
        line-height: 26px;
        cursor: pointer;
        position: absolute;
        top: 50%;
        margin-top: -10px;
        z-index: 3;
    }

    #left {
        left: 0;
    }

    #right {
        right: 0;
    }
</style>

<body>
    <div class="lunbo">
        <div class="wrap">
            <div class="btnBox">
                <span id="left">&lt;</span>
                <span id="right">&gt;</span>
            </div>
            <div class="wraps">
                <img src="http://www.photophoto.cn/m1/005/004/0050040031.jpg" />
                <img src="http://www.photophoto.cn/m1/005/004/0050040001.jpg" />
                <img src="http://www.photophoto.cn/m36/005/018/0050180021.jpg" />
            </div>
            <p class="page"></p>
        </div>
    </div>
</body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/swipe/2.0.0/swipe.js'></script>
<script>

    $(function () {
        $(".wraps img:not(:first)").hide();
        var index = 0;
        var s = $(".wraps img").length;
        var auto;
        for (var i = 1; i <= s; i++) {
            $(".page").append("<span></span>");
        }
        $(".page span:first").addClass("current");
        $(".page span").on("click", function () {
            index = $(this).index();
            move();
        });
        function autos() {
            auto = setInterval(function () {
                index++;
                if (index == s) {
                    index = 0;
                }
                move();
            }, 3000);
        }
        autos();
        function move() {
            $(".page span").eq(index).addClass("current").siblings().removeClass('current');
            $(".wraps img").eq(index).stop(true, true).fadeIn().siblings().stop(true, true).fadeOut();
        }
        $("#left").click(function () {
            clearInterval(auto);
            index--;
            if (index <= -1) {
                index = s - 1;
            }
            move();
            autos();
        });
        $("#right").click(function () {
            clearInterval(auto);
            index++;
            if (index >= s) {
                index = 0;
            }
            move();
            autos();
        });
        $(".wraps img, .page span").mouseover(function () {
            clearInterval(auto);
        }).mouseout(function () {
            autos();
        });
    });

</script>

</html>

 

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值