小米商城轮播图

要求

1.自动播放
2.鼠标移入暂停播放,鼠标移除回复播放
3.点击左右箭头鼠标,切换图片
4.点击右下方源点,切换图片
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>轮播图</title>
    <script src="js/jquery-3.4.0.js"></script>
    <style>
        *{
            padding: 0px;
            margin: 0px;
        }
        #box{
            height: 460px;
            width: 1226px;
            margin: 30px auto;
            position: relative;
        }
        #box .img{
            list-style: none;
        }
        #box .img li{
            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }
        #box .left{
            width: 41px;
            height: 69px;
            position: absolute;
            left:20px;
            top:195px;
            background-image: url("images/icon-slides.png");
            background-position: -83px 0;
        }
        #box .right{
            width: 41px;
            height: 69px;
            position: absolute;
            right:20px;
            top:195px;
            background-image: url("images/icon-slides.png");
            background-position: -124px 0;
        }
        #box .left:hover{
            background-position: 0 0;
        }
        #box .right:hover{
            background-position: -42px 0;
        }
        #box .focus{
            width: 250px;
            height: 20px;
            position: absolute;
            right: 20px;
            bottom: 20px;
        }
        #box .focus span{
            float: left;
            width: 15px;
            height: 15px;
            border-radius: 50%;
            background-color: gray;
            margin-left: 15px;
        }
        #box .focus .content{
            background-color: gainsboro;
        }
    </style>

    <script>
        $(function () {
            function changeImg(num) {
                $(".img li").eq(num).fadeIn().siblings().fadeOut();
                $(".focus span").eq(num).addClass("content").siblings().removeClass("content");
            }

            var num = 0;
            //1、实现自动播放
            var timer = 0;
            function autoPlay() {
                timer =  setInterval(function () {
                    num++;
                    num = (num == 7 ? 0 : num);
                    /*num = (num==7?0:num);*/
                    changeImg(num)
                },2000)
            }
            autoPlay();
            $("#box").mouseenter(function () {
                clearInterval(timer);
            }).mouseleave(function () {
                clearInterval(timer);
                autoPlay();
            })

            //4、点击左右的箭头,切换图片
            $("#box .left").click(function () {
                num--;
                num = num == -1 ? 6 : num;
                changeImg(num);
            })
            $("#box .right").click(function () {
                num++;
                num = num == 7 ? 0 : num;
                changeImg(num);
            })
            $("#box .focus span").click(function () {
                num = $(this).index();
                changeImg(num);
            })
        })
    </script>
</head>
<body>
    <div id="box">
            <ul class="img">
                <li  style=" display:block;"><img src="images/ban01.jpg" height="460" width="1226"/></li>
                <li><img src="images/ban02.jpg" height="460" width="1226"/></li>
                <li><img src="images/ban03.jpg" height="460" width="1226"/></li>
                <li><img src="images/ban04.jpg" height="460" width="1226"/></li>
                <li><img src="images/ban05.jpg" height="460" width="1226"/></li>
                <li><img src="images/ban06.jpg" height="460" width="1226"/></li>
                <li><img src="images/ban07.jpg" height="460" width="1226"/></li>
            </ul>
        <a class="left"></a>
        <a class="right"></a>
        <div class="focus">
            <span class="content" ></span>
            <span></span>
            <span></span>
            <span></span>
            <span></span>
            <span></span>
            <span></span>
        </div>
    </div>
</body>
</html>

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值