web前端-快速理解swiper(滑动)

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

<head>
    <meta charset="utf-8">
    <title>swiper</title>
    <link rel="stylesheet" href="./packages/swiper.min.css">
    <style>
        .banner {
            width: 400px;
            height: 200px;
            background-color: chocolate;
            text-align: center;
            line-height: 200px;
        }

        .banner .swiper-slide {
            width: 400px;
        }

        /* 自定义分页器容器 */
        .pagination {
            text-align: center;
            font-size: 0;
            line-height: 0;
            vertical-align: top;
        }

        /* 自定义分页器子元素未选中 */
        .bullet {
            display: inline-block;
            background-color: cyan;
            width: 20px;
            height: 20px;
            margin: 0 5px;
            color: #856a31;
            font-size: 16px;
            line-height: 20px;
            text-align: center;
        }

        /* 自定义分页器子元素已选中 */
        .bullet-active {
            background-color: darkblue;
            color: #fff;
        }

        /* 自定义导航按钮-前 */
        .prevEl {
            background-color: darkred;
            width: 30px;
            height: 30px;
            margin: 0 auto;
        }
        
        /* 自定义导航按钮-后 */
        .nextEl {
            background-color:goldenrod;
            width: 30px;
            height: 30px;
            margin: 0 auto;
        }
    </style>
</head>

<body>
    <!-- 
        container为显示区域
        一般会加个类名区别,万一一个页面不止这个滑动呢
    -->
    <div class="swiper-container banner">
        <!-- wrapper内容,一般水平扩展会超出视野 -->
        <div class="swiper-wrapper">
            <!-- 具体每个滑块大小 -->
            <div class="swiper-slide">Slide 1</div>
            <div class="swiper-slide">Slide 2</div>
            <div class="swiper-slide">Slide 3</div>
        </div>
    </div>
    <!-- 自定义分页器和导航按钮,写在container外头 -->
    <!-- 分页器 -->
    <div class="pagination"></div>
    <!-- 导航按钮前 -->
    <div class="prevEl"></div>
    <!-- 导航按钮后 -->
    <div class="nextEl"></div>

    <!-- js部分 -->
    <script src="./packages/swiper.js"></script>
    <script>
        var swiper = new Swiper('.banner', {
            pagination: {
                el: '.pagination',
                clickable: true,
                // 自定义分页器未选中类名
                bulletClass: 'bullet',
                // 自定义分页器选中后类名
                bulletActiveClass: 'bullet-active',
                // 给分页器加数字用
                renderBullet: function (index, className) {
                    return '<span class="' + className + '">' + (index + 1) + '</span>';
                },
            },
            navigation: {
                prevEl: '.prevEl',
                nextEl: '.nextEl',
            },
        });
    </script>
</body>

</html>

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值