• 用swiper实现不规则分页滚动 & 给分页器加颜色


    效果图

    移动端想实现这样的效果, 可以先安装swiper

    npm install swiper
    

    template代码:

    <div class="swiper-container">
                    <div class="swiper-wrapper">
                        <div class="swiper-slide">
                            <img src="../../../assets/images/mobile/invoicepickup/swiper_banner.png">
                        </div>
                        <div class="swiper-slide">
                            <img src="../../../assets/images/mobile/invoicepickup/swiper_banner.png">
                        </div>
                        <div class="swiper-slide">
                            <img src="../../../assets/images/mobile/invoicepickup/swiper_banner.png">
                        </div>
                    </div>
                    <!-- 如果需要分页器 -->
                    <div class="swiper-pagination"></div>
    
                    <!-- 如果需要导航按钮 -->
                    <!--                <div class="swiper-button-prev"></div>-->
                    <!--                <div class="swiper-button-next"></div>-->
    
                    <!-- 如果需要滚动条 -->
                    <!--    <div class="swiper-scrollbar"></div>-->
                </div>
    

     JS代码

    new Swiper ('.swiper-container', {
                loop: true,
                // 如果需要分页器
                pagination: '.swiper-pagination',
                // 如果需要前进后退按钮
                // nextButton: '.swiper-button-next',
                // prevButton: '.swiper-button-prev',
                // 如果需要滚动条
                // scrollbar: '.swiper-scrollbar',
                //如果需要自动切换海报
                // autoplay: {
                //   delay: 1,//时间 毫秒
                //   disableOnInteraction: true,//用户操作之后是否停止自动轮播默认true
                // },
                slidesPerView: 'auto',//默认一个屏幕显示几张图,必须auto!
                centeredSlides: true,//每屏,居中显示
                spaceBetween: 10
            });
    

     CSS关键代码

    .swiper-slide{
            padding:0 0.5rem !important;
        }
    

     其他代码依据实际需要增减

    给分页器加颜色:

        .swiper-pagination >>> .swiper-pagination-bullet-active{
            background-color: white;
    
        }
    
    此文仅为鄙人学习笔记之用,朋友你来了,如有不明白或者建议又或者想给我指点一二,请私信我。liuw_flexi@163.com/QQ群:582039935. 我的gitHub: (学习代码都在gitHub) https://github.com/nwgdegitHub/
  • 相关阅读:
    URL传参到servlet含特殊字符——#号无法传递
    textarea标签中间出现空格问题
    MySQL学习笔记(23)——自定义函数
    修改日期插件问题
    获取Spring的ApplicationContext的方法
    数据库用户被锁
    ava获得当前文件路径
    前端框架
    LeetCode 485. 最大连续1的个数
    LeetCode 283. 移动零
  • 原文地址:https://www.cnblogs.com/liuw-flexi/p/14366635.html
Copyright © 2020-2023  润新知