Swiper的使用
.js文件
var imgUrls = [=
{ image: "http://www.padmag.cn/wp-content/uploads/Unforgiven.jpg" },
{ image: "http://www.padmag.cn/wp-content/uploads/Desire.jpg" },
{ image: "http://www.padmag.cn/wp-content/uploads/No_Goodbye.jpg" },
{ image: "http://www.padmag.cn/wp-content/uploads/Look_Away.jpg" }
]
Page({
data: {
imgUrls: imgUrls,
autoplay: true,
indicatorDots: true,
interval: 5000,
duration: 500,
indicatorColor: "blue",
indicatorActiveColor: "white",
current: 2,
circular: true
}, imageLoad: function () {
this.setData({
imageWidth: wx.getSystemInfoSync().windowWidth
})
}, swiperChange: function () {
console.log("current 改变时会触发 change 事件")
}
})
.wxml文件
<swiper indicator-dots="{{indicatorDots}}" current="{{current}}" circular="{{circular}}" indicator-active-color="{{indicatorActiveColor}}" indicator-color="{{indicatorColor}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" bindchange="swiperChange">
<block wx:for="{{imgUrls}}" wx:key="image">
<swiper-item>
<image src="{{item.image}}" model="aspectFit" style="width: {{imageWidth}}px;" bindload="imageLoad" />
</swiper-item>
</block>
</swiper>