注冊

微信小程序滑塊視圖容器swiper,微信小程序swiper實例

2017-12-22
導(dǎo)讀:swiper 滑塊視圖容器。 屬性名 類型 默認(rèn)值 說明 最低版本 indicator-dots Boolean false 是否顯示面板指示點 indicator-color Color rgba(0, 0, 0, .3) 指示點顏色 1.1.0 indicator-active-color Color #000000 當(dāng)前選中...

swiper


滑塊視圖容器。

 

屬性名 類型 默認(rèn)值 說明 最低版本
indicator-dots Boolean false 是否顯示面板指示點  
indicator-color Color rgba(0, 0, 0, .3) 指示點顏色 1.1.0
indicator-active-color Color #000000 當(dāng)前選中的指示點顏色 1.1.0
autoplay Boolean false 是否自動切換  
current Number 0 當(dāng)前所在頁面的 index  
interval Number 5000 自動切換時間間隔  
duration Number 500 滑動動畫時長  
circular Boolean false 是否采用銜接滑動  
vertical Boolean false 滑動方向是否為縱向  
bindchange EventHandle   current 改變時會觸發(fā) change 事件,event.detail = {current: current, source: source}  

 

從公共庫v1.4.0開始,change事件返回detail中包含一個source字段,表示導(dǎo)致變更的原因,可能值如下:

  • autoplay自動播放導(dǎo)致swiper變化;
  • touch用戶劃動引起swiper變化;
  • 其他原因?qū)⒂每兆址硎尽?/li>

注意:其中只可放置<swiper-item/>組件,否則會導(dǎo)致未定義的行為。

swiper-item

僅可放置在<swiper/>組件中,寬高自動設(shè)置為100%。

 

示例代碼:

<swiper indicator-dots="{{indicatorDots}}"
  autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
  <block wx:for="{{imgUrls}}">
    <swiper-item>
      <image src="{{item}}" class="slide-image" width="355" height="150"/>
    </swiper-item>
  </block>
</swiper>
<button bindtap="changeIndicatorDots"> indicator-dots </button>
<button bindtap="changeAutoplay"> autoplay </button>
<slider bindchange="intervalChange" show-value min="500" max="2000"/> interval
<slider bindchange="durationChange" show-value min="1000" max="10000"/> duration
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: false,
    autoplay: false,
    interval: 5000,
    duration: 1000
  },
  changeIndicatorDots: function(e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay: function(e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange: function(e) {
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange: function(e) {
    this.setData({
      duration: e.detail.value
    })
  }
})
更多微信小程序開發(fā)教程,可以關(guān)注hi小程序。
重磅推薦:小程序開店目錄

第一部分:小商店是什么

第二部分:如何開通一個小商店

第三部分:如何登錄小商店

第四部分:開店任務(wù)常見問題

第五部分:小商店可以賣什么

第六部分:HiShop小程序特色功能

第七部分:小程序直播

第八部分:小程序收貨/物流

第九部分:小程序怎么結(jié)算

第十部分:小程序客服

第十一部分:電商創(chuàng)業(yè)

第十二部分:小程序游戲開發(fā)