1. 程式人生 > >微信小程式之輪播元件:swiper

微信小程式之輪播元件:swiper

swiper,輪播圖片,叫滑塊檢視容器。效果很屌的哦

官方文件例子很好:

https://mp.weixin.qq.com/debug/wxadoc/dev/component/swiper.html

先上最終效果:


啦啦啦,程式碼:



樣式無所謂的啦,定義你自己喜歡的就好。

<swiper>

<swiper>標籤中只可以放置<swiper-item>

常用屬性:

indicator-dots :預設為false,是否顯示面板指示點,肯定是true好看呀;

indicator-color:這個是指示點顏色;

autoplay:預設false,是否自動切換,輪播嘛,肯定也是true;

interval:預設5000毫秒,自動切換的時間間隔

duration:預設500,滑動動畫的時長,這個我沒改過

circular:預設false,是否採用銜接滑動

vertical:預設false,將滑動方向改為縱向

display-mltiple-items:預設1,同時顯示的滑塊數

事件:

bindchange:改變時觸發事件。在回撥setData改變current值,應判斷source是否由使用者觸控事件,避免setData不停呼叫。

bindanimationfinish:動畫結束後觸發事件

兩個事件的event.detail={current:current,source:source(返回變更原因)}

<swiper-item>僅可以放在<swiper>中,寬高自動設定為100%

屬性

item-id : 標識id