gpt4 book ai didi

javascript - 在 swiper.js 上,添加停止、播放按钮

转载 作者:行者123 更新时间:2023-12-05 05:14:35 27 4
gpt4 key购买 nike

在 swiper.js 上,我尝试在自动 slider 上添加播放、停止按钮。所以我试过这样

$(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>

但是停止,播放按钮对我不起作用。我错过了什么?有人知道吗?
请帮忙。

最佳答案

使用您分配给 swiper 的变量。

var homeSwiper = new Swiper('.home_top_swiper', {
// …

$(".swiper-button-pause").click(function(){
homeSwiper.autoplay.stop();
});

$(".swiper-button-play").click(function(){
homeSwiper.autoplay.start();
});
}

关于javascript - 在 swiper.js 上,添加停止、播放按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52325510/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com