vue中使用swiper(一页显示3张图片)遇到的坑以及解决方案

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue中使用swiper(一页显示3张图片)遇到的坑以及解决方案相关的知识,希望对你有一定的参考价值。

参考技术A 请看效果,对比上面的那个图,是不是就好多了呢

Swiper滚动图片显示当前图片是第几张图片

滑动到下一张图片时数字变为2/40,求大神解答。

参考技术A /*单个切换的幻灯片 s*/
.banner
position: relative;
overflow: hidden;

.banner-publicHt
height: 396px;

.img-box
display: inline-block;
width: 100%;

.swiper-slide
text-align: center;
font-size: 36px;
background: #fff;
/* Center slide text vertically */
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-pack: left;
-ms-flex-pack: left;
-webkit-justify-content: left;
justify-content: left;
-webkit-box-align: left;
-ms-flex-align: left;
-webkit-align-items: left;
align-items: left;

.banner .swiper-slide img
width: 100%;

.banner .swiper-pagination-bullet-active
background: url("/img/off.png") no-repeat;

.banner .swiper-pagination-bullet
background: url("/img/on.png") no-repeat;

.banner .swiper-container-horizontal>.swiper-pagination
left: 160px;

.num-check
position: absolute;
right: 0;
bottom: 0px;
background-color: #000;
opacity: 0.7;
width: 100%;
height: 50px;
z-index: 998;

.num-choose
position: absolute;
right: 5%;
bottom: 0px;
color: #FCFBFB;
font-size: 22px;
display: inline-block;
width: 90%;
height: 50px;
line-height: 50px;
z-index: 999;
text-align: right;

/*单个切换的幻灯片 e*/

<div class="banner banner-publicHt">
<!--单个幻灯片 s-->
<div class="swiper-container banner-publicHt">
<div class="swiper-wrapper">
<div class="swiper-slide">
<a class="img-box" href="javascript:void(0);">
<img class="banner-publicHt" src="../swiper/img/banner1.jpg">
</a>
</div>
<div class="swiper-slide">
<a class="img-box" href="javascript:void(0);">
<img class="banner-publicHt" src="../swiper/img/banner2.jpg">
</a>
</div>
<div class="swiper-slide">
<a class="img-box" href="javascript:void(0);">
<img class="banner-publicHt" src="../swiper/img/banner2.jpg">
</a>
</div>
<div class="swiper-slide">
<a class="img-box" href="javascript:void(0);">
<img class="banner-publicHt" src="../swiper/img/banner2.jpg">
</a>
</div>
<div class="swiper-slide">
<a class="img-box" href="javascript:void(0);">
<img class="banner-publicHt" src="../swiper/img/banner2.jpg">
</a>
</div>
</div>
<!-- Add Pagination -->
<div class="swiper-pagination" style="display: none;"></div>
<div class="num-check">
<p class="num-choose">
<span class="checkLength"></span>
/
<span class="allImgLength"></span>
</p>
</div>
</div>
<!--单个幻灯片 e-->
</div>
$(function()
$(".checkLength").html(1);
/*单个切换的幻灯效果*/
var swiper = new Swiper('.banner .swiper-container',
pagination: '.banner .swiper-pagination',
paginationClickable: true,
spaceBetween: 30,
/*每隔5秒就进行一次图片切换*/
autoplay:5000,
// direction: 'vertical',
/*用户操作之后(swipes,arrow以及pagination 点击)autoplay不会被禁掉*/
autoplayDisableOnInteraction:false,
onSlideChangeStart: function(swiper)
$(".checkLength").html(swiper.activeIndex+1);

);
/*获取图片长度*/
var imgAllLength = $(".swiper-slide .banner-publicHt").length;
console.log(imgAllLength);
$(".allImgLength").html(imgAllLength);

/*图片报错或者为空的时候默认现在这张图片*/
$(".banner-publicHt").on('error',function()
$(this).prop('src','../swiper/img/banner1.jpg');
)
)

以上是关于vue中使用swiper(一页显示3张图片)遇到的坑以及解决方案的主要内容,如果未能解决你的问题,请参考以下文章

vue中轮播组件,实现默认显示3张图片,中间显示全部两边显示部分

vue图片轮播一次显示三张且中间一张图片可以放大缩小

swiper轮播始终居中active图片

Vue与swiper想结合封装全屏轮播插件

vue中使用vue-awesome-swiper

移动端swiper做页面切换,如何让做最后一页滑动时回到第一页