python ----基于jquery的轮播图

本文详细介绍了一种基于HTML和CSS的轮播图实现方法,包括图片切换效果、导航按钮和指示器的交互设计。通过jQuery实现了轮播图的自动播放、鼠标悬停暂停和点击切换功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!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">
    <title>轮播图</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            list-style: none;
        }

        .box1 {
            position: relative;
            width: 790px;
            height: 340px;
            margin: 100px auto;
        }

        .box1 li {
            position: absolute;

            display: none;
        }

        .box1 li:first-child {
            display: block;
        }

        .arrow {
            display: none;
        }

        .box1:hover .arrow {
            display: block;
        }

        .arrow-left,
        .arrow-right {
            width: 30px;
            height: 60px;
            background-color: rgba(0, 0, 0, 0.1);
            /*background-color: #e53935;*/
            position: absolute;
            top: 50%;
            margin-top: -30px;
            cursor: pointer;
            text-align: center;
            line-height: 60px;
            color: #fff;
            font-size: 30px;
        }

        .arrow-left {
            left: 0;
        }

        .arrow-right {
            right: 0
        }

        .arrow-left:hover,
        .arrow-right:hover {
            background-color: rgba(0, 0, 0, .5);
        }

        .circles {
            position: absolute;
            left: 20px;
            bottom: 20px;
        }

        .circles > i {
            width: 12px;
            height: 12px;
            border: 2px solid #fff;
            border-radius: 50%;
            display: inline-block;
            margin-left: 8px;

        }

        .circles > i.on {
            background-color: #fff;
        }
    </style>
</head>
<body>
<script src="../day14/jquery-3.0.0.js"></script>
<div class="box1">
    <ul class="picbox">
        <li><a href="#"><img src="img/1.jpg"></a></li>
        <li><a href="#"><img src="img/2.jpg"></a></li>
        <li><a href="#"><img src="img/3.jpg"></a></li>
        <li><a href="#"><img src="img/4.jpg"></a></li>
        <li><a href="#"><img src="img/5.jpg"></a></li>
        <li><a href="#"><img src="img/6.jpg"></a></li>
        <li><a href="#"><img src="img/7.jpg"></a></li>
        <li><a href="#"><img src="img/8.jpg"></a></li>
    </ul>
    <div class="arrow">a
        <span class="arrow-left">&lt;</span>
        <span class="arrow-right">&gt;</span>
    </div>
    <div class="circles">
        <i class="on" a="0"></i>
        <i a="1"></i>
        <i a="2"></i>
        <i a="3"></i>
        <i a="4"></i>
        <i a="5"></i>
        <i a="6"></i>
        <i a="7"></i>
    </div>
</div>
<script>
    $(function () {
        var $lookbox = $('.box1');
        var index = 0;
        $('.arrow-right').click(function () {
            MyToogle(1);
            buttonshow()

        });
        $('.arrow-left').click(function () {
            MyToogle(0);
            buttonshow()

        });

        function MyToogle(flag) {
            if (flag === 0) {
                index--;
                if (index === -1) {
                    index = 7
                }
            }
            else {
                index++;
                if (index === 8) {
                    index = 0;
                }
            }
            $('.picbox').find('li').eq(index).fadeIn(1000).siblings().fadeOut(1000)

        }

        function play() {
            timer = setInterval(function () {
                MyToogle(1);
                buttonshow()

            }, 1000)

        }

        play();
        $lookbox.mouseover(function () {
            clearInterval(timer)

        });
        $lookbox.mouseout(function () {
            play()

        });

        function buttonshow() {
            $('.circles>i').removeClass('on');
            $('.circles>i').eq(index).addClass('on')

        }

        $('.circles>i').mouseover(function () {
            var newindex = $(this).attr('a');
            $('.circles>i').removeClass('on');
            $(this).addClass('on');
            $('.picbox>li').eq(newindex).fadeIn(300).siblings().fadeOut(300)

        })

    })

</script>

</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值