Swiper轮播

    引入

    在app.json或index.json中引入组件,默认为ES6版本

    1. "usingComponents": {
    2. "vtu-swiper": "/miniprogram_npm/vtuweapp/swiper/vtu-swiper"
    3. }

    代码演示

    卡片式轮播用法

    1. <vtu-swiper type="card" height="{{(windowWidth-40)/2}}px" list="{{imageList}}" swiper-class="swiperClass" indicator-dots="{{true}}" current="{{current}}" bind:change="bindChange"></vtu-swiper>
    2. Page({
    3. data: {
    4. current: 1,
    5. imageList: [
    6. {
    7. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/1.png',
    8. mode: "widthFix"
    9. },
    10. {
    11. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/2.png',
    12. mode: "widthFix"
    13. },
    14. {
    15. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/3.png',
    16. mode: "widthFix"
    17. },
    18. {
    19. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/4.png',
    20. mode: "widthFix"
    21. },
    22. {
    23. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/5.png',
    24. mode: "widthFix"
    25. }
    26. ],
    27. imageList2: [
    28. {
    29. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/2.png',
    30. content: '红米7大电量18个月质保智能学生老年人全网通手机小米官方旗舰店redmi7A官网正品xiaomi红米note7',
    31. mode: "widthFix"
    32. },
    33. {
    34. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/4.png',
    35. content: 'OPPO K3 oppok3手机全新机新款上市oppok3限量超薄oppoa5手机 a7x r17oppor15x 0ppok3r90pp0k1',
    36. mode: "widthFix"
    37. },
    38. {
    39. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/1.png',
    40. content: '12期分期可减540当天发Huawei/华为 P30手机官方旗舰店正品p30荣耀p30pro直降mate20x新款5g全网通p10 p20pro',
    41. mode: "widthFix"
    42. },
    43. {
    44. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/3.png',
    45. content: '【选送小米27W快充头】Xiaomi/小米 Redmi K20Pro骁龙855红米K20手机官方旗舰弹出全面屏4800万广角三摄note7',
    46. mode: "widthFix"
    47. },
    48. {
    49. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/5.png',
    50. content: '可12期免息【抢360券+送无线充】xiaomi/小米9手机plus官方旗舰店骁龙855透明尊享版九Mix4红米K20小米9学生',
    51. mode: "widthFix"
    52. }
    53. ],
    54. windowWidth: wx.getSystemInfoSync().windowWidth
    55. },
    56. bindChange: function(e) {
    57. this.setData({
    58. current: e.detail.current
    59. })
    60. }
    61. });
    62.  

    基础用法

    1. <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>
    2. Page({
    3. data: {
    4. current: 1,
    5. imageList: [
    6. {
    7. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/1.png',
    8. mode: "widthFix"
    9. },
    10. {
    11. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/2.png',
    12. mode: "widthFix"
    13. },
    14. {
    15. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/3.png',
    16. mode: "widthFix"
    17. },
    18. {
    19. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/4.png',
    20. mode: "widthFix"
    21. },
    22. {
    23. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/5.png',
    24. mode: "widthFix"
    25. }
    26. ],
    27. imageList2: [
    28. {
    29. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/2.png',
    30. content: '红米7大电量18个月质保智能学生老年人全网通手机小米官方旗舰店redmi7A官网正品xiaomi红米note7',
    31. mode: "widthFix"
    32. },
    33. {
    34. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/4.png',
    35. content: 'OPPO K3 oppok3手机全新机新款上市oppok3限量超薄oppoa5手机 a7x r17oppor15x 0ppok3r90pp0k1',
    36. mode: "widthFix"
    37. },
    38. {
    39. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/1.png',
    40. content: '12期分期可减540当天发Huawei/华为 P30手机官方旗舰店正品p30荣耀p30pro直降mate20x新款5g全网通p10 p20pro',
    41. mode: "widthFix"
    42. },
    43. {
    44. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/3.png',
    45. content: '【选送小米27W快充头】Xiaomi/小米 Redmi K20Pro骁龙855红米K20手机官方旗舰弹出全面屏4800万广角三摄note7',
    46. mode: "widthFix"
    47. },
    48. {
    49. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/5.png',
    50. content: '可12期免息【抢360券+送无线充】xiaomi/小米9手机plus官方旗舰店骁龙855透明尊享版九Mix4红米K20小米9学生',
    51. mode: "widthFix"
    52. }
    53. ],
    54. windowWidth: wx.getSystemInfoSync().windowWidth
    55. },
    56. bindChange: function(e) {
    57. this.setData({
    58. current: e.detail.current
    59. })
    60. }
    61. });

    字幕轮播

    1. <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>
    2. Page({
    3. data: {
    4. current: 1,
    5. imageList: [
    6. {
    7. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/1.png',
    8. mode: "widthFix"
    9. },
    10. {
    11. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/2.png',
    12. mode: "widthFix"
    13. },
    14. {
    15. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/3.png',
    16. mode: "widthFix"
    17. },
    18. {
    19. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/4.png',
    20. mode: "widthFix"
    21. },
    22. {
    23. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/5.png',
    24. mode: "widthFix"
    25. }
    26. ],
    27. imageList2: [
    28. {
    29. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/2.png',
    30. content: '红米7大电量18个月质保智能学生老年人全网通手机小米官方旗舰店redmi7A官网正品xiaomi红米note7',
    31. mode: "widthFix"
    32. },
    33. {
    34. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/4.png',
    35. content: 'OPPO K3 oppok3手机全新机新款上市oppok3限量超薄oppoa5手机 a7x r17oppor15x 0ppok3r90pp0k1',
    36. mode: "widthFix"
    37. },
    38. {
    39. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/1.png',
    40. content: '12期分期可减540当天发Huawei/华为 P30手机官方旗舰店正品p30荣耀p30pro直降mate20x新款5g全网通p10 p20pro',
    41. mode: "widthFix"
    42. },
    43. {
    44. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/3.png',
    45. content: '【选送小米27W快充头】Xiaomi/小米 Redmi K20Pro骁龙855红米K20手机官方旗舰弹出全面屏4800万广角三摄note7',
    46. mode: "widthFix"
    47. },
    48. {
    49. url: 'https://activity.vtuzx.com/doc/vtuUI/weapp/swiper/5.png',
    50. content: '可12期免息【抢360券+送无线充】xiaomi/小米9手机plus官方旗舰店骁龙855透明尊享版九Mix4红米K20小米9学生',
    51. mode: "widthFix"
    52. }
    53. ],
    54. windowWidth: wx.getSystemInfoSync().windowWidth
    55. },
    56. bindChange: function(e) {
    57. this.setData({
    58. current: e.detail.current
    59. })
    60. }
    61. });

    组件参数

    Props

    参数说明类型默认值必填
    type类型,default/cardString-
    list轮播图片列表Array-
    indicator-dots是否显示面板指示点Booleanfalse
    indicator-color指示点颜色Stringrgba(0, 0, 0, .3)
    indicator-active-color选中指示点颜色Stringrgba(109,109,109,0.76)
    autoplay是否自动切换Booleanfalse
    current当前索引Number0
    interval切换时间间隔Number5000
    duration滑动时长Number500
    circular是否采用衔接滑动Booleanfalse
    vertical滑动方向是否为纵向Booleanfalse
    easing-function指定 swiper 切换缓动动画类型Stringdefault
    display-multiple-items同时显示的滑块数量Number1
    dot-font-color轮播文本字体颜色String"#fff"
    height轮播区域高度String-

    easing-function 的合法值

    说明
    default默认缓动函数
    linear线性动画
    easeInCubic缓入动画
    easeOutCubic缓出动画
    easeInOutCubic缓入缓出动画

    list参数值

    参数说明类型默认值必填
    url轮播图片链接地址String-
    mode图片裁剪、缩放的模式(参考微信文档)StringwidthFix
    content文本轮播内容String-

    Events

    方法名说明参数返回值
    bind:changecurrent 改变时会触发 change 事件,event.detail = {current, source}--
    bind:transitionswiper-item 的位置发生改变时会触发 transition 事件,event.detail = {dx: dx, dy: dy}--
    bind:animationfinish动画结束时会触发 animationfinish 事件,event.detail 同上--

    外部样式类

    外部样式类名说明
    v-class组件外部样式类

    Swiper 轮播 - 图1