在swiper.js上,添加停止、播放按钮
2018-09-14
11694
在 swiper.js 上,我尝试在自动滑块上添加播放、停止按钮。 所以我尝试了这样的方法
$(function() {
var homeSwiper = new Swiper('.home_top_swiper', {
pagination: '.swiper-pagination',
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
paginationClickable: true,
autoplay: 3000,
autoplayDisableOnInteraction: true,
loop: true,
autoHeight: true
});
$(".swiper-button-pause").click(function(){
Swiper.autoplay.stop();
});
$(".swiper-button-play").click(function(){
Swiper.autoplay.play();
});
});
<div class="home_top_swiper">
<div class="swiper-wrapper">
<div class="swiper-slide">11 </div>
<div class="swiper-slide">22 </div>
<div class="swiper-slide">33 </div>
</div>
<div class="swiper-button-prev">prev</div>
<div class="swiper-button-next">next</div>
<div class="swiper-button-play">play</div>
<div class="swiper-button-pause">stop</div>
</div>
但是停止、播放按钮对我来说不起作用。
我错过了什么?有人知道吗?
请帮忙。
1个回答
使用您分配给 swiper 的变量。
var homeSwiper = new Swiper('.home_top_swiper', {
// …
$(".swiper-button-pause").click(function(){
homeSwiper.autoplay.stop();
});
$(".swiper-button-play").click(function(){
homeSwiper.autoplay.start();
});
}
mdell3072
2019-07-10