swiper

Swiper view container.

Attribute NameTypeDefaultDescriptionMinimum Version
indicator-dotsBooleanfalseshow indicator or not
indicator-colorColorrgba(0, 0, 0, .3)indicator color
indicator-active-colorColor#000color of currently selected indicator
autoplayBooleanfalseauto switch or not
currentNumber0current page index
durationNumber500(ms)swipe animation duration
intervalNumber5000(ms)auto switch interval
circularBooleanfalseenable infinite swipe or not
verticalBooleanfalseis swipe direction vertical or not
onChangeEventHandleNotrigger on current change, event.detail = {current, current}

Swiper-item

Can place in component or not; width and height are automatically set as 100%.

Sceenshot

swiper

Sample Code

copy
<swiper
  indicator-dots="{{indicatorDots}}"
  autoplay="{{autoplay}}"
  interval="{{interval}}"
>
  <block a:for="{{background}}">
    <swiper-item>
      <view class="swiper-item bc_{{item}}"></view>
    </swiper-item>
  </block>
</swiper>
<view class="btn-area">
  <button class="btn-area-button" type="default" onTap="changeIndicatorDots">indicator-dots</button>
  <button class="btn-area-button" type="default" onTap="changeAutoplay">autoplay</button>
</view>
<slider onChange="intervalChange" value="{{interval}}" show-value min="2000" max="10000"/>
<view class="section__title">interval</view>
copy
Page({
  data: {
    background: ['green', 'red', 'yellow'],
    indicatorDots: true,
    autoplay: false,
    interval: 3000,
  },
  changeIndicatorDots(e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay(e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange(e) {
    this.setData({
      interval: e.detail.value
    })
  },
})