微信小程序-swiper組件

滑塊視圖容器
常用屬性:


注意:swiper中只可放置<swiper-item/>組件,其他節(jié)點會被自動刪除。
效果圖:

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"/> 滑動動畫時長

swiper.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
    })
  },
  //當頁面改變是會觸發(fā)
  bindchangeTag:function(e){
    console.log("bindchangeTag...")
  }, 
  onLoad:function(options){
    // 頁面初始化 options為頁面跳轉所帶來的參數(shù)
  },
  onReady:function(){
    // 頁面渲染完成
  },
  onShow:function(){
    // 頁面顯示
  },
  onHide:function(){
    // 頁面隱藏
  },
  onUnload:function(){
    // 頁面關閉
  }
})

swiper.wxss添加代碼:

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

來源:
http://bbs.520it.com/forum.php?mod=viewthread&tid=2566&extra=page%3D1

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容