第五篇、微信小程序-swiper組件


常用屬性:

 

效果圖:

 

swiper.wxml添加代碼:

<swiper indicator-dots="{{indicatorDots}}"
  autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}} " bindchange="bindchangeTag">
  <block wx:for="{{imgUrls}}">
    <swiper-item>
      <image src="{{item}}" class="slide-image"/>
    </swiper-item>
  </block>
</swiper>
<button bindtap="changeIndicatorDots"> 是否顯示面板指示點 </button>
<button bindtap="changeAutoplay"> 是否自動切換 </button>
<slider bindchange="intervalChange" show-value min="1000" max="2000"/> 自動切換時間間隔
<slider bindchange="durationChange" show-value min="1800" max="10000"/> 滑動動畫時長

 

js:

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: 1000,
    duration: 1800
  },
  //是否顯示面板指示點
  changeIndicatorDots: function(e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  //是否自動切換
  changeAutoplay: function(e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  //自動切換時間間隔
  intervalChange: function(e) {
    this.setData({
      // e.detail.value獲取slider的值
      interval: e.detail.value
    })
  },
  //滑動動畫時長
  durationChange: function(e) {
    this.setData({
      duration: e.detail.value
    })
  },
  //當頁面改變是會觸發
  bindchangeTag:function(e){
    console.log("bindchangeTag...")
  }, 
  onLoad:function(options){
    // 頁面初始化 options為頁面跳轉所帶來的參數
  },
  onReady:function(){
    // 頁面渲染完成
  },
  onShow:function(){
    // 頁面顯示
  },
  onHide:function(){
    // 頁面隱藏
  },
  onUnload:function(){
    // 頁面關閉
  }
})

 

css:

.slide-image{
    width: 100%;
    height: 160px;
}

 


免責聲明!

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



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