微信小程序_(組件)swiper輪播圖

 

 

  微信小程序swiper輪播圖組件官方文檔  傳送門html

  

 

  Learn:小程序

    swiper組件微信小程序

 

 

1、swiper組件微信

  indicator-dots:是否顯示面板指示點【默認值false】ide

  autoplay:是否自動切換【默認值false】函數

  interval:自動切換時間間隔【默認值5000】動畫

  duration:滑動動畫時長【默認值500】this

 

  swiper滑塊組件代碼,初始化indicator-dots,autoplay,interval,duration四個屬性spa

<swiper
  indicator-dots="{{indicatorDots}}"
  autoplay="{{autoplay}}"
  interval="{{interval}}"
  duration="{{duration}}"
>
  <block wx:for="{{imgUrls}}" wx:key="">
    <swiper-item>
      <image src="{{item}}" class="slide-image" width="355" height="150" />
    </swiper-item>
  </block>
</swiper>

 

  添加<button>組件綁定函數,去修改indicator-dots,autoplay,interval,duration四個屬性code

<button bindtap="changeIndicatorDots">indicator-dots</button>
<button bindtap="changeAutoplay">autoplay</button>
interval自動切換時間間隔
<slider bindchange="intervalChange" show-value min="500" max="2000" />
duration滑動動畫時長
<slider bindchange="durationChange" show-value min="1000" max="10000" />

 

 

<!--index.wxml-->
Cynical丶Gary
<!-- 創建swiper代碼塊 -->
<swiper
  indicator-dots="{{indicatorDots}}"
  autoplay="{{autoplay}}"
  interval="{{interval}}"
  duration="{{duration}}"
>
  <block wx:for="{{imgUrls}}" wx:key="">
    <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>
interval自動切換時間間隔
<slider bindchange="intervalChange" show-value min="500" max="2000" />
duration滑動動畫時長
<slider bindchange="durationChange" show-value min="1000" max="10000" />
index.html

 

Page({
  data: {
    imgUrls: [
      'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',
      'https://images.unsplash.com/photo-1551214012-84f95e060dee?w=640',
      'https://images.unsplash.com/photo-1551446591-142875a901a1?w=640'
    ],
    indicatorDots: false,
    autoplay: false,
    interval: 5000,
    duration: 1000
  },
  changeIndicatorDots(e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay(e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange(e) {
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange(e) {
    this.setData({
      duration: e.detail.value
    })
  }
})
index.js
相關文章
相關標籤/搜索