微信小程序swiper实现轮播图,可触发点击事件

实现微信小程序轮换图切换,点击获取图片url,获取当前位置

1、index.js

Page({  

    data: {
        autoplay: true,
        dotsBoll: false,
        interval: 2000,
        duration: 1000,
        current:0,
        imageUrls: [
            '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'
        ]
    },
    intervalChange: function (e) {//自动切换时间间隔
        this.setData({
            interval: e.detail.value
        })
    },
    durationChange: function (e) {//滑动动画时长
        duration: e.detail.value
    },
    changeIndicatorDots: function (e) {//是否显示小圆圈
        this.setData({
            dotsBoll: !this.data.dotsBoll
        })
    },
    changeAutoplay: function (e) {//是否自动播放
        this.setData({
            autoplay: !this.data.autoplay
        })
    },
    swipclick: function (e) {//点击图片触发事件
        console.log(this.data.imageUrls[this.data.current]);
    },
    bindchange:function(e){//轮播图发生改变
        this.setData({
            current:e.detail.current
        })
    }
})

2、index.wxml

<swiper indicator-dots="{{dotsBoll}}" interval="{{interval}}" duration="{{duration}}" autoplay="{{autoplay}}" bindchange="bindchange">
    <block wx:for-items="{{imageUrls}}">
        <swiper-item >
            <image src="{{item}}" height="150" width="355" bindtap="swipclick"></image>
        </swiper-item>
    </block>
</swiper>
<button bindtap="changeIndicatorDots"> indicator-dots </button>
<button bindtap="changeAutoplay"> autoplay </button>
<slider bindchange="intervalChange" show-value min="500" max="2000"/>
<slider bindchange="durationChange" show-value min="1000" max="10000"/>



评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值