微信小程序的轮播功能

广告:宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取~~~

微信小程序的轮播功能

我们在官网上可以看到轮播相关的说明了,这里是通过一个实例来说明一下微信小程序的轮播功能的实现效果:

先看一下效果图:

JS代码:

var app = getApp();Page({    data: {        imgUrls: [            'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',            'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',            'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'        ],        indicatorDots: true,        autoplay: false,        interval: 5000,        duration: 1000    },    changeIndicatorDots: function(e) {        this.setData({            indicatorDots: !this.data.indicatorDots        })    },    changeAutoplay: function(e) {        this.setData({            autoplay: !this.data.autoplay        })    },    intervalChange: function(e) {        this.setData({            interval: e.detail.value        })    },    durationChange: function(e) {        this.setData({            duration: e.detail.value        })    },})
登录后复制

data中是要设置的数据。indicatorDots设置是否有点,interval设置每隔多少毫秒进行切换,duration设置切换的速度。中对所有的照片进行遍历。这些值通过data然后在函数中进行设置。

WXML代码:

<swiper indicator-dots="{{indicatorDots}}"        autoplay="true" interval="5000" duration="1000">    <block wx:for="{{imgUrls}}">        <swiper-item>            <image src="{{item}}" class="slide-image" width="400" height="150"/>        </swiper-item>    </block></swiper>
登录后复制

以上就是这个轮播的的过程,主要应用组件,autoplay设置是否自动播放,interval设置每隔多少毫秒进行切换,duration设置切换的速度。中对所有的照片进行遍历。通过简单的配置可以达到轮播的效果,还是非常容易实现的。

更多微信小程序的轮播功能相关文章请关注PHP中文网!

9543建站博客
一个专注于网站开发、微信开发的技术类纯净博客。
作者头像
admin创始人

肥猫,知名SEO博客站长,14年SEO经验。

上一篇:yii怎么显示调试信息
下一篇:C#开发微信门户及应用微信企业号的通讯录管理开发之部门管理

发表评论

关闭广告
关闭广告