swiper,關於滑塊的一些效果無縫,斷點,視差等等...我想這裏就不用作太多的贅述,這裏給你們分享一下實戰項目中使用circular(銜接)的一點小特性、小技巧,固然你也能夠理解爲遇到了一個小坑,由於不能把整個項目搬上來,因此這裏用一個小事例去簡單的描述一下。html
swiper滑塊視圖容器(輪播效果)ide
這裏只簡單列出示例中所需的一些屬性,如需瞭解更多【請點擊,瞭解更多詳情】oop
indicatorDots: true, // 是否顯示面板指示點
autoplay: false, // 是否自動切換
circular: true, // 是否採用銜接滑動
current: 0, // 當前所在頁面的 index
interval: 500, // 自動切換時間間隔
duration: 500 // 滑動動畫時長
複製代碼
類答題效果,答對本題自動跳轉下一題,並保持滑塊的銜接效果(這裏咱們用按鈕來代替自動跳轉)flex
<page>
<view class='wrap-swiper'>
<swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" circular="{{circular}}" current="{{current}}" bindchange='testDetails' indicator-active-color='#fff'>
<block wx:for="{{imgUrls}}" wx:key="key">
<swiper-item>
<image src="https://user-gold-cdn.xitu.io/2018/1/15/160f8b440965adf5" class="slide-image" width="355" height="150" />
</swiper-item>
</block>
</swiper>
<view class="wrap">
<button bindtap='nextPage'>跳轉下一題</button>
</view>
</view>
</page>
複製代碼
swiper{
width: 80%;
margin: 0 auto;
margin-top: 20%;
padding-top: 25px;
}
.wrap{
display: flex;
justify-content: space-around;
margin-top: 25px;
}
.wrap-swiper{
background: rgba(0,0,0, 0.1) ;
padding-bottom: 25px;
margin-left: 15px;
margin-right: 15px;
}
複製代碼
Page({
data: {
imgUrls: [
'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
],
indicatorDots: true, // 是否顯示面板指示點
autoplay: false, // 是否自動切換
circular: true, // 是否採用銜接滑動
current: 0, // 當前所在頁面的 index
interval: 500, // 自動切換時間間隔
duration: 500 // 滑動動畫時長
},
testDetails (e) {
// bindchange事件
console.log(e)
},
nextPage () {
// 跳轉下一題
let current = this.data.current
current++
if (current > 2) {
current = 0
}
}
})
複製代碼
經過上述,首先咱們看到,當咱們左右滑動時候,銜接效果是沒有毛病的,可是當咱們去模擬跳轉的時候,問題出現了,銜接失效?這到底是怎麼回事呢?如今咱們就來看一下在bindchange事件(testDetails)的兩次log中發生了什麼?動畫
如上圖所屬,source(來源) 出現問題,模擬跳轉改變current方式改變了內部銜接跳轉的機制,那既然知道緣由,那下一步的就要考慮如何模擬swiper內部的機制動做,那又該如何模擬呢?就要從autoplay這個內置屬性操刀了,廢話不說直接上代碼!this
Page({
data: {
imgUrls: [
'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
],
indicatorDots: true, // 是否顯示面板指示點
autoplay: false, // 是否自動切換
circular: true, // 是否採用銜接滑動
current: 0, // 當前所在頁面的 index
interval: 500, // 自動切換時間間隔
duration: 500 // 滑動動畫時長
},
testDetails (e) {
console.log(e)
if (e.detail.source == 'autoplay') {
this.setData({
autoplay: false
})
}
},
nextPage () {
// 跳轉下一題
this.setData({
autoplay: true
})
}
})
複製代碼
本篇文章更多的是對於一些用法的分享,簡單的特性說明,更深層次的內容,有興趣的道友仍是能夠去研究下的,另外歡迎你們關注點贊,多謝!(持續更新中...)spa
(注:封面來源於互聯網,若有侵權,請聯繫做者刪除;如需轉載,請附原文連接及署名,多謝)debug