美文网首页
swiper中间大两边小的轮播图

swiper中间大两边小的轮播图

作者: 生于乱世 | 来源:发表于2020-08-29 09:50 被阅读0次
8C039727-1ADE-4b37-BA03-C151164FF8F0.png

首先引入swiper官网的css和js
html代码如下

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Swiper的切换</title>
        <link rel="stylesheet" href="css/swiper.min.css">
        <link rel="stylesheet" href="css/certify.css">
        <script src="js/swiper.min.js"></script>

    </head>
    <body>
        <div id="certify">
            <div class="swiper-container">
                <div class="swiper-wrapper">
                    <div class="swiper-slide"><img src="images/certify01.png" />
                        <p>非常难得又值钱的认证证书</p>
                    </div>
                    <div class="swiper-slide"><img src="images/certify02.png" />
                        <p>深圳市优秀互联网企业认定证书</p>
                    </div>
                    <div class="swiper-slide"><img src="images/certify03.png" />
                        <p>质量管理体系认证荣誉证书</p>
                    </div>
                    <div class="swiper-slide"><img src="images/certify04.png" />
                        <p>计算机软件著作权登记证书</p>
                    </div>
                    <div class="swiper-slide"><img src="images/certify05.png" />
                        <p>增值电信业务经营许可证</p>
                    </div>
                </div>
            </div>
            <div class="swiper-pagination"></div>
            <div class="swiper-button-prev"></div>
            <div class="swiper-button-next"></div>
        </div>

        <script>
            certifySwiper = new Swiper('#certify .swiper-container', {
                watchSlidesProgress: true,
                slidesPerView: 'auto',
                centeredSlides: true,
                loop: true,
                loopedSlides: 5,
                autoplay: 3000,
                prevButton: '.swiper-button-prev',
                nextButton: '.swiper-button-next',
                pagination: '.swiper-pagination',
                //paginationClickable :true,
                onProgress: function(swiper, progress) {
                    for (i = 0; i < swiper.slides.length; i++) {
                        var slide = swiper.slides.eq(i);
                        var slideProgress = swiper.slides[i].progress;
                        modify = 1;
                        if (Math.abs(slideProgress) > 1) {
                            modify = (Math.abs(slideProgress) - 1) * 0.3 + 1;
                        }
                        translate = slideProgress * modify * 260 + 'px';
                        scale = 1 - Math.abs(slideProgress) / 5;
                        zIndex = 999 - Math.abs(Math.round(10 * slideProgress));
                        slide.transform('translateX(' + translate + ') scale(' + scale + ')');
                        slide.css('zIndex', zIndex);
                        slide.css('opacity', 1);
                        if (Math.abs(slideProgress) > 3) {
                            slide.css('opacity', 0);
                        }
                    }
                },
                onSetTransition: function(swiper, transition) {
                    for (var i = 0; i < swiper.slides.length; i++) {
                        var slide = swiper.slides.eq(i)
                        slide.transition(transition);
                    }

                },
                //处理分页器bug
                onSlideChangeStart: function(swiper) {
                    if (swiper.activeIndex == 4) {
                        swiper.bullets.eq(9).addClass('swiper-pagination-bullet-active');
                        console.log(swiper.bullets.length);
                    }
                }
            });
        </script>
    </body>
</html>

css部分

@charset "utf-8";
/* CSS Document */

#certify {
    position: relative;
    width: 1200px;
    margin: 0 auto
}

#certify .swiper-container {
    padding-bottom: 60px;
}

#certify  .swiper-slide {
    width: 520px;
    height: 408px;
    background: #fff;
    box-shadow: 0 8px 30px #ddd;
}
#certify  .swiper-slide img{
    display:block;
}
#certify  .swiper-slide p {
    line-height: 98px;
    padding-top: 0;
    text-align: center;
    color: #636363;
    font-size: 1.1em;
    margin: 0;
}

#certify .swiper-pagination {
    width: 100%;
    bottom: 20px;
}

#certify .swiper-pagination-bullets .swiper-pagination-bullet {
    margin: 0 5px;
    border: 3px solid #fff;
    background-color: #d5d5d5;
    width: 10px;
    height: 10px;
    opacity: 1;
}

#certify .swiper-pagination-bullets .swiper-pagination-bullet-active {
    border: 3px solid #00aadc;
    background-color: #fff;
}

#certify .swiper-button-prev {
    left: -30px;
    width: 45px;
    height: 45px;
    background: url(../images/wm_button_icon.png) no-repeat;
    background-position: 0 0;
    background-size: 100%;
}

#certify .swiper-button-prev:hover {
    background-position: 0 -46px;
    background-size: 100%
}

#certify .swiper-button-next {
    right: -30px;
    width: 45px;
    height: 45px;
    background: url(../images/wm_button_icon.png) no-repeat;
    background-position: 0 -93px;
    background-size: 100%;
}

#certify .swiper-button-next:hover {
    background-position: 0 -139px;
    background-size: 100%
}

相关文章

网友评论

      本文标题:swiper中间大两边小的轮播图

      本文链接:https://www.haomeiwen.com/subject/hwyyrktx.html