前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >五分钟掌握微信小程序轮播图

五分钟掌握微信小程序轮播图

作者头像
企鹅号小编
发布2018-01-30 14:16:51
8000
发布2018-01-30 14:16:51
举报
文章被收录于专栏:微信小开发

从公共库v1.4.0开始,change事件返回detail中包含一个source字段,表示导致变更的原因,可能值如下:

autoplay 自动播放导致

swiper

变化;

touch 用户划动引起swiper变化;

其他原因将用空字符串表示。

注意:其中只可放置

组件,否则会导致未定义的行为。

swiper-item

仅可放置在

组件中,宽高自动设置为100%。

swiper { height: 421.5rpx; } swiper-item image { width: 100%; height: 100%; } .swiper-container{ position: relative; } .swiper-container .swiper{ height: 300rpx; } .swiper-container .swiper .img{ width: 100%; height: 100%; }

index.js

Page({ data: { swiperCurrent: 0, indicatorDots: true, autoplay: true, interval: 3000, duration: 800, circular:true, imgUrls: [ 'https://p3.pstatp.com/large/43700001e49d85d3ab52', 'https://p3.pstatp.com/large/39f600038907bf3b9c96', 'https://p3.pstatp.com/large/31fa0003ed7228adf421' ], links:[ '../user/user', '../user/user', '../user/user' ] }, //轮播图的切换事件 swiperChange: function (e) { this.setData({ swiperCurrent: e.detail.current }) }, //点击指示点切换 chuangEvent: function (e) { this.setData({ swiperCurrent: e.currentTarget.id }) }, //点击图片触发事件 swipclick: function (e) { console.log(this.data.swiperCurrent); wx.switchTab({ url: this.data.links[this.data.swiperCurrent] }) } })

重要一点是图片的点击事件,官网没明确指出。

bindtap="swipclick"

效果图

五分钟掌握微信小程序轮播图

本文来自企鹅号 - 洪生鹏媒体

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文来自企鹅号 - 洪生鹏媒体

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云开发 CloudBase
云开发(Tencent CloudBase,TCB)是腾讯云提供的云原生一体化开发环境和工具平台,为200万+企业和开发者提供高可用、自动弹性扩缩的后端云服务,可用于云端一体化开发多种端应用(小程序、公众号、Web 应用等),避免了应用开发过程中繁琐的服务器搭建及运维,开发者可以专注于业务逻辑的实现,开发门槛更低,效率更高。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档