swiper 三张图片滑动,第二张居中,其他分别位于二端显示部分

关键css代码样式:

.swiper-container-banner .swiper-slide{
   width: 800px!important;
   margin: 0 calc(50% - 400px);
}
.swiper-container-banner .swiper-slide-prev{
   right: calc(825px - 100vw);
}
.swiper-container-banner .swiper-slide-next{
   left: calc(825px - 100vw);
}

设置的图片大小,宽度为800px;
上面代码的825px的原因是,需要图片之间有间隙,可以根据情况微调。
关键性的属性:vw

拓展:vw是可视窗口的宽度单位,1vw = 可视窗口的宽度的百分之一。和百分比不一样的是,vw始终相对于可视窗口的宽度,而百分比是和其父元素的宽度有关的。

js代码:

 //首页banner
 var mySwiper = new Swiper('.swiper-container-banner', {
     direction: 'horizontal',
     autoplay: {
         delay: 2500,
         disableOnInteraction: false,
     },
     //centeredSlides:true,
     slidesPerView : 'auto',
     loop:true,
     //spaceBetween: 20
 });

效果如下:
swiper 三张图片滑动,第二张居中,其他分别位于二端显示部分_第1张图片
swiper 三张图片滑动,第二张居中,其他分别位于二端显示部分_第2张图片

你可能感兴趣的:(css)