Swiper轮播
引入
在app.json或index.json中引入组件,默认为ES6版本
"usingComponents": {
"vtu-swiper": "/miniprogram_npm/vtuweapp/swiper/vtu-swiper"
}
代码演示
卡片式轮播用法
<vtu-swiper type="card" height="{{(windowWidth-40)/2}}px" list="{{imageList}}" swiper-class="swiperClass" indicator-dots="{{true}}" current="{{current}}" bind:change="bindChange"></vtu-swiper>
Page({
data: {
current: 1,
imageList: [
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/1.png',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/2.png',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/3.png',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/4.png',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/5.png',
mode: "widthFix"
}
],
imageList2: [
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/2.png',
content: '红米7大电量18个月质保智能学生老年人全网通手机小米官方旗舰店redmi7A官网正品xiaomi红米note7',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/4.png',
content: 'OPPO K3 oppok3手机全新机新款上市oppok3限量超薄oppoa5手机 a7x r17oppor15x 0ppok3r90pp0k1',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/1.png',
content: '12期分期可减540当天发Huawei/华为 P30手机官方旗舰店正品p30荣耀p30pro直降mate20x新款5g全网通p10 p20pro',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/3.png',
content: '【选送小米27W快充头】Xiaomi/小米 Redmi K20Pro骁龙855红米K20手机官方旗舰弹出全面屏4800万广角三摄note7',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/5.png',
content: '可12期免息【抢360券+送无线充】xiaomi/小米9手机plus官方旗舰店骁龙855透明尊享版九Mix4红米K20小米9学生',
mode: "widthFix"
}
],
windowWidth: wx.getSystemInfoSync().windowWidth
},
bindChange: function(e) {
this.setData({
current: e.detail.current
})
}
});
基础用法
<vtu-swiper list="{{imageList}}" height="{{(windowWidth-40)/2}}px" dot-type="round" indicator-active-color="#3fe816" swiper-class="swiperClass" indicator-dots="{{true}}" current="{{current}}" bind:change="bindChange"></vtu-swiper>
Page({
data: {
current: 1,
imageList: [
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/1.png',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/2.png',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/3.png',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/4.png',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/5.png',
mode: "widthFix"
}
],
imageList2: [
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/2.png',
content: '红米7大电量18个月质保智能学生老年人全网通手机小米官方旗舰店redmi7A官网正品xiaomi红米note7',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/4.png',
content: 'OPPO K3 oppok3手机全新机新款上市oppok3限量超薄oppoa5手机 a7x r17oppor15x 0ppok3r90pp0k1',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/1.png',
content: '12期分期可减540当天发Huawei/华为 P30手机官方旗舰店正品p30荣耀p30pro直降mate20x新款5g全网通p10 p20pro',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/3.png',
content: '【选送小米27W快充头】Xiaomi/小米 Redmi K20Pro骁龙855红米K20手机官方旗舰弹出全面屏4800万广角三摄note7',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/5.png',
content: '可12期免息【抢360券+送无线充】xiaomi/小米9手机plus官方旗舰店骁龙855透明尊享版九Mix4红米K20小米9学生',
mode: "widthFix"
}
],
windowWidth: wx.getSystemInfoSync().windowWidth
},
bindChange: function(e) {
this.setData({
current: e.detail.current
})
}
});
字幕轮播
<vtu-swiper list="{{imageList2}}" height="{{(windowWidth-40)/2}}px" dot-type="content" swiper-content-class="swiperContentClass" indicator-active-color="rgba(0, 0, 0, .5)" dot-font-color="#fff" swiper-class="swiperClass" indicator-dots="{{true}}" current="{{current}}" bind:change="bindChange"></vtu-swiper>
Page({
data: {
current: 1,
imageList: [
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/1.png',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/2.png',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/3.png',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/4.png',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/5.png',
mode: "widthFix"
}
],
imageList2: [
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/2.png',
content: '红米7大电量18个月质保智能学生老年人全网通手机小米官方旗舰店redmi7A官网正品xiaomi红米note7',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/4.png',
content: 'OPPO K3 oppok3手机全新机新款上市oppok3限量超薄oppoa5手机 a7x r17oppor15x 0ppok3r90pp0k1',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/1.png',
content: '12期分期可减540当天发Huawei/华为 P30手机官方旗舰店正品p30荣耀p30pro直降mate20x新款5g全网通p10 p20pro',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/3.png',
content: '【选送小米27W快充头】Xiaomi/小米 Redmi K20Pro骁龙855红米K20手机官方旗舰弹出全面屏4800万广角三摄note7',
mode: "widthFix"
},
{
url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/5.png',
content: '可12期免息【抢360券+送无线充】xiaomi/小米9手机plus官方旗舰店骁龙855透明尊享版九Mix4红米K20小米9学生',
mode: "widthFix"
}
],
windowWidth: wx.getSystemInfoSync().windowWidth
},
bindChange: function(e) {
this.setData({
current: e.detail.current
})
}
});
组件参数
Props
参数 | 说明 | 类型 | 默认值 | 必填 |
---|
type | 类型,default/card | String | - | 否 |
list | 轮播图片列表 | Array | - | 否 |
indicator-dots | 是否显示面板指示点 | Boolean | false | 否 |
indicator-color | 指示点颜色 | String | rgba(0, 0, 0, .3) | 否 |
indicator-active-color | 选中指示点颜色 | String | rgba(109,109,109,0.76) | 否 |
autoplay | 是否自动切换 | Boolean | false | 否 |
current | 当前索引 | Number | 0 | 否 |
interval | 切换时间间隔 | Number | 5000 | 否 |
duration | 滑动时长 | Number | 500 | 否 |
circular | 是否采用衔接滑动 | Boolean | false | 否 |
vertical | 滑动方向是否为纵向 | Boolean | false | 否 |
easing-function | 指定 swiper 切换缓动动画类型 | String | default | 否 |
display-multiple-items | 同时显示的滑块数量 | Number | 1 | 否 |
dot-font-color | 轮播文本字体颜色 | String | "#fff" | 否 |
height | 轮播区域高度 | String | - | 否 |
easing-function 的合法值
值 | 说明 |
---|
default | 默认缓动函数 |
linear | 线性动画 |
easeInCubic | 缓入动画 |
easeOutCubic | 缓出动画 |
easeInOutCubic | 缓入缓出动画 |
list参数值
参数 | 说明 | 类型 | 默认值 | 必填 |
---|
url | 轮播图片链接地址 | String | - | 否 |
mode | 图片裁剪、缩放的模式(参考微信文档) | String | widthFix | 否 |
content | 文本轮播内容 | String | - | 否 |
Events
方法名 | 说明 | 参数 | 返回值 |
---|
bind:change | current 改变时会触发 change 事件,event.detail = {current, source} | - | - |
bind:transition | swiper-item 的位置发生改变时会触发 transition 事件,event.detail = {dx: dx, dy: dy} | - | - |
bind:animationfinish | 动画结束时会触发 animationfinish 事件,event.detail 同上 | - | - |
外部样式类
外部样式类名 | 说明 |
---|
v-class | 组件外部样式类 |