微信小程序視圖容器 swiper

2022-05-11 16:04 更新

swiper


基礎(chǔ)庫 1.0.0 開始支持,低版本需做兼容處理。

滑塊視圖容器。

屬性 類型 默認(rèn)值 必填 說明 最低版本
indicator-dots boolean false 是否顯示面板指示點(diǎn) 1.0.0
indicator-color color rgba(0, 0, 0, .3) 指示點(diǎn)顏色 1.1.0
indicator-active-color color #000000 當(dāng)前選中的指示點(diǎn)顏色 1.1.0
autoplay boolean false 是否自動(dòng)切換 1.0.0
current number 0 當(dāng)前所在滑塊的 index 1.0.0
interval number 5000 自動(dòng)切換時(shí)間間隔 1.0.0
duration number 500 滑動(dòng)動(dòng)畫時(shí)長 1.0.0
circular boolean false 是否采用銜接滑動(dòng) 1.0.0
vertical boolean false 滑動(dòng)方向是否為縱向 1.0.0
previous-margin string "0px" 前邊距,可用于露出前一項(xiàng)的一小部分,接受 px 和 rpx 值 1.9.0
next-margin string "0px" 后邊距,可用于露出后一項(xiàng)的一小部分,接受 px 和 rpx 值 1.9.0
display-multiple-items number 1 同時(shí)顯示的滑塊數(shù)量 1.9.0
skip-hidden-item-layout boolean false 是否跳過未顯示的滑塊布局,設(shè)為 true 可優(yōu)化復(fù)雜情況下的滑動(dòng)性能,但會(huì)丟失隱藏狀態(tài)滑塊的布局信息 1.9.0
easing-function string "default" 指定 swiper 切換緩動(dòng)動(dòng)畫類型 2.6.5
bindchange eventhandle current 改變時(shí)會(huì)觸發(fā) change 事件,event.detail = {current, source} 1.0.0
bindtransition eventhandle swiper-item 的位置發(fā)生改變時(shí)會(huì)觸發(fā) transition 事件,event.detail = {dx: dx, dy: dy} 2.4.3
bindanimationfinish eventhandle 動(dòng)畫結(jié)束時(shí)會(huì)觸發(fā) animationfinish 事件,event.detail 同上 1.9.0

easing-function 的合法值

說明 最低版本
default 默認(rèn)緩動(dòng)函數(shù)
linear 線性動(dòng)畫
easeInCubic 緩入動(dòng)畫
easeOutCubic 緩出動(dòng)畫
easeInOutCubic 緩入緩出動(dòng)畫


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

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

注意:如果在 bindchange 的事件回調(diào)函數(shù)中使用 setData 改變 current 值,則有可能導(dǎo)致 setData 被不停地調(diào)用,因而通常情況下請(qǐng)?jiān)诟淖?nbsp; current 值前檢測 source 字段來判斷是否是由于用戶觸摸引起。

swiper-item

基礎(chǔ)庫 1.0.0 開始支持,低版本需做兼容處理。

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

屬性 類型 默認(rèn)值 必填 說明 最低版本
item-id string 該 swiper-item 的標(biāo)識(shí)符 1.9.0

示例代碼:

<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
    })
  }
})


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)