framework7框架訪問地址:https://framework7.io/vue/swiper.html
Swiper API : http://idangero.us/swiper/api/
中文版 Swiper API: https://www.swiper.com.cn/api/
本代碼使用framework7+vue框架,使用了Swiper API來解決輪播滑動問題。
一開始代碼是這樣的,注意 示例不能運行,調試時發現,頁面加載出來的時候圖片可以輪播,但是手動滑動之后,頁面的圖片不再自動輪播。
一開始代碼是這樣的,注意 示例不能運行,調試時發現,頁面加載出來的時候圖片可以輪播,但是手動滑動之后,頁面的圖片不再自動輪播。
1 ... 2 <f7-swiper v-if="bannerList.length" :params="swiperParams" pagination ref="mySwiper"> 3 <f7-swiper-slide v-for="banner in bannerList" :key="banner.id"> 4 </f7-swiper-slide> 5 </f7-swiper> 6 <script> 7 export default { 8 data () { 9 swiperParams: { 10 speed: 500, 11 loop: true, 12 autoplay: { 13 delay: 2500, 14 }, 15 preventLinksPropagation: false // 阻止點擊事件冒泡 16 }, 17 } 18 } 19 </script>
官網示例是這樣的,f7引用的格式不一樣,但是配置方法是一致的。
1 var mySwiper = new Swiper('.swiper-container', { 2 speed: 500, 3 loop: true, 4 autoplay: { 5 delay: 2500, 6 } 7 ... 8 });
然后查詢官方Swiper API : http://idangero.us/swiper/api/,通過慢慢摸索,找到了一個可以解決手動滑動后,自動滑動失效問題。
屬性名:disableOnInteraction:
屬性值:boolean true
解釋:Set to false and autoplay will not be disabled after user interactions (swipes), it will be restarted every time after interaction
中文意思就是:當disableOnInteraction:false 的時候,手動滑動之后,自動滑動不會失效,每次手動滑動之后,自動滑動會再開啟。
屬性值:boolean true
解釋:Set to false and autoplay will not be disabled after user interactions (swipes), it will be restarted every time after interaction
中文意思就是:當disableOnInteraction:false 的時候,手動滑動之后,自動滑動不會失效,每次手動滑動之后,自動滑動會再開啟。
修改后的代碼:
注意:disableOnInteraction是autoplay的屬性。
1 <f7-swiper v-if="bannerList.length" :params="swiperParams" pagination ref="mySwiper"> 2 <f7-swiper-slide v-for="banner in bannerList" :key="banner.id"> 3 </f7-swiper-slide> 4 </f7-swiper> 5 <script> 6 export default { 7 data () { 8 swiperParams: { 9 speed: 500, 10 loop: true, 11 autoplay: { 12 disableOnInteraction: false, 13 delay: 2500, 14 }, 15 preventLinksPropagation: false // 阻止點擊事件冒泡 16 }, 17 } 18 } 19 </script>
官方示例寫法:
var mySwiper = new Swiper('.swiper-container', { speed: 500, loop: true, autoplay: { disableOnInteraction: false, delay: 2500, } ... });
原文鏈接:https://www.jianshu.com/p/f1c6395314f2