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


 

 

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

  

 

  Learn:

    swiper組件

 

 

一、swiper組件

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

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

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

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

 

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

<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四個屬性

<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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM