zoukankan      html  css  js  c++  java
  • 用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/
  • 相关阅读:
    [网络] 第五章 运输层
    pubwin
    R语言
    我的微博开通啦
    迅雷使用积分制的真正作用和目的 [揭密迅雷]
    求数组里面第二大的数
    xp环境下安装vmware workstation 7出错
    一道大学c语言作业题
    写在断网的那些日子里
    mysql里奇怪的日期201627 14:28:15
  • 原文地址:https://www.cnblogs.com/liuw-flexi/p/14366635.html
Copyright © 2011-2022 走看看