swiper实现响应式全屏自动轮播

html:

<!--轮播 -->
    <div class="Excellent_swi">
        <div class="swiper-container">
            <div class="swiper-wrapper">
                <div class="swiper-slide">
                    <img class="banner" src="https://dummyimage.com/1920x800/000/fff" />
                </div>
                <div class="swiper-slide">
                    <img class="banner" src="https://dummyimage.com/1920x400/00f/fff" />
                </div>
                <div class="swiper-slide">
                    <img class="banner" src="https://dummyimage.com/1920x400/0f0/fff" />
                </div>
            </div>
            <!-- Add Pagination -->
            <div class="swiper-pagination"></div>
            <!-- Add Arrows -->
            <div class="swiper-button-next"></div>
            <div class="swiper-button-prev"></div>
        </div>
    </div>

css:要结合swiper.css使用

.Excellent_swi {
    width: 100%;
    height: 100%;
}

.swiper-container {
    width: 100%;
    height: 100%;
    margin-left: auto;
    margin-right: auto;
}
//图片水平垂直居中
.swiper-slide {
    text-align: center;
    font-size: 18px;
    background: #fff;
    /* Center slide text vertically */
    display: -webkit-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    -webkit-justify-content: center;
    justify-content: center;
    -webkit-box-align: center;
    -ms-flex-align: center;
    -webkit-align-items: center;
    align-items: center;
}

.swiper-pagination-bullet {
    width: 25px;
    height: 5px;
    display: inline-block;
    border-radius: 0;
    opacity: 0.5;
    background: #FFFFFF;
}

.swiper-pagination-bullet-active {
    background: #C6A771;
}

.swiper-button-prev,
.swiper-container-rtl .swiper-button-next {
    background-image: url();
}
//让图片响应屏幕
.banner {
    width: 100%;
}

js:

var swiper = new Swiper('.swiper-container', {
            spaceBetween: 30,
            centeredSlides: true,
            autoplay: {
                delay: 2500,
                disableOnInteraction: false,
            },
            pagination: {
                el: '.swiper-pagination',
                clickable: true,
            },
            navigation: {
                nextEl: '.swiper-button-next',
                prevEl: '.swiper-button-prev',
            },
        });

 

转载于:https://www.cnblogs.com/jervy/p/9639014.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值