swiper自定义分页器

问题:不想使用swiper(用的是4.5.1版本)的自带的圆钮式的分页器,需要自定义样式同时分页器需要摆在图片外面

解决办法:利用swiper提供的renderCustom()方法

html文件

js文件

var mySwiper = new Swiper ('.swiper-container', {
        autoplay: {
            delay: 3000,
            disableOnInteraction: false
        },
        pagination: {
            el: '.swiper-pagination',
            type: 'custom',
            renderCustom: function (swiper, current, total) {
                var customPaginationHtml = "";
                for(var i = 0; i < total; i++) {
                    // 判断哪个分页器此刻应该被激活
                    if(i == (current - 1)) {
                        customPaginationHtml += '';
                    } else {
                        customPaginationHtml += '';
                    }
                }
                return customPaginationHtml;
            }
        },
    });

css文件

.swiper-box{
    position: relative;
    margin: 0 auto;
}
.swiper-container{
    width: 74vw;
    height: 34vw;
    margin-top: 4vw;
}
.swiper-container .swiper-slide img{
    width: 100%;
}
.swiper-pagination{
    text-align: center;
    width: 74vw;
}
.swiper-pagination-bullet{
    margin: 4vw
}
/* 包裹自定义分页器的div的位置的样式 */
.swiper-pagination-custom {
    bottom: -5vw;
}
.swiper-pagination-customs {
    background-image: url(../img/point-grey.png); /* 未轮播到的图片分页样式 */
    display: inline-block;
    background-repeat: no-repeat;
    background-size: contain;
    width: 1.4vw;
    height: 1.4vw;
    margin-left: 2vw;
}
/*自定义分页器激活时的样式表现*/
.swiper-pagination-customs-active {
    background-image: url(../img/point-green.png);
}

效果如下:

你可能感兴趣的:(swiper.js,css)