上面卡片正常滑动,点击下面的小卡牌,切换到当前的对应的卡片。
原生 js 版
<section>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">女皇
<p class="card-btn">送给朋友一张</p>
</div>
<div class="swiper-slide">世界
<p class="card-btn">送给朋友一张</p>
</div>
<div class="swiper-slide">星星
<p class="card-btn">送给朋友一张</p>
</div>
<div class="swiper-slide">月亮
<p class="card-btn">送给朋友一张</p>
</div>
<div class="swiper-slide">魔术师
<p class="card-btn">送给朋友一张</p>
</div>
<div class="swiper-slide">太阳
<p class="card-btn">送给朋友一张</p>
</div>
</div>
</div>
<div class="contrast-box">
<ul>
<li data-index="5">魔术师</li>
<li data-index="6">太阳</li>
<li data-index="1">女皇</li>
<li data-index="2">世界</li>
<li data-index="3">星星</li>
<li data-index="4">月亮</li>
<li class="combin-btn">合成</li>
</ul>
</div>
<div class="button-next"></div>
<div class="button-prev"></div>
</section>
var mySwiper = new Swiper('.swiper-container', {
nextButton: '.button-next',
prevButton: '.button-prev',
effect: 'coverflow', //3d滑动
grabCursor: true,
centeredSlides: true, // 居中
slidesPerView: 'auto',
loop: true,
slidesPerView: 2, // 显示2个
coverflow: {
rotate: 0, //设置为0
stretch: 0,
depth: 200,
modifier: 2,
slideShadows: true
}
})
$('.contrast-box').on('click', ()=> {
var _index = $(this).data('index') + 1
mySwiper.slideTo(_index, 500, false)//切换到第一个slide,速度为1秒
})
$('.button-prev').click(()=> mySwiper.slidePrev())
$('.button-next').click(()=> mySwiper.slideNext())