左右滑動(dòng)可以切換展示圖片:
<!--pages/test/test.wxml--> <!-- 組件 --> <swiper> <swiper-item wx:for="{{imgUrls}}"> <image src='{{item}}' width="335" height="150" mode='widthFix' class='img' /> </swiper-item> </swiper>
pages/test/test.js:
// pages/test/test.js Page({ data: { imgUrls:[ 'http://dl.bizhi.sogou.com/images/1440x900/2014/05/14/611368.jpg', 'http://dl.bizhi.sogou.com/images/1440x900/2013/10/19/394877.jpg', 'http://img04.sogoucdn.com/app/a/100520093/ca86e620b9e623ff-d72d635343d5bade-dcf2acda7a45cb44f172db138bdf8d2d.jpg', ] }, //事件處理函數(shù) toupper:function(){ console.log("觸發(fā)了toupper"); } })
pages/test/test.wxss:
.img{ width: 100%; }
心得:
swiper組件:滑塊視圖容器。
可以為swiper添加autoplay屬性,是之自動(dòng)播放,例如:autoplay=”true”
swiper組件中使用的是image單標(biāo)簽,而不是雙標(biāo)簽(否則報(bào)錯(cuò))。
推薦:《小程序開發(fā)教程》