您好,登錄后才能下訂單哦!
本文實(shí)例為大家分享了微信小程序輪播圖的具體代碼,供大家參考,具體內(nèi)容如下
1.邏輯層
mine.js
// pages/mine/mine.js Page({ /** * 頁(yè)面的初始數(shù)據(jù) */ 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, // 是否顯示面板指示點(diǎn) autoplay: true, // 是否自動(dòng)切換 interval: 5000, // 自動(dòng)切換時(shí)間間隔 duration: 500, // 滑動(dòng)動(dòng)畫時(shí)長(zhǎng) circular: true, // 是否采用銜接滑動(dòng) /*自定義輪播圖 配置*/ slider: [ { id: '0', linkUrl: 'pages/index/index', picUrl: 'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg' }, { id: '0', linkUrl: 'pages/index/index', picUrl: 'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg' }, { id: '0', linkUrl: 'pages/index/index', picUrl: 'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg' } ], swiperCurrent: 0 }, /** * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載 */ onLoad: function (options) { }, //輪播圖的切換事件 swiperChange: function (e) { //只要把切換后當(dāng)前的index傳給<swiper>組件的current屬性即可 this.setData({ swiperCurrent: e.detail.current }) }, //點(diǎn)擊指示點(diǎn)切換 chuangEvent: function (e) { this.setData({ swiperCurrent: e.currentTarget.id }) } })
2.頁(yè)面布局
mine.wxml
<!--pages/mine/mine.wxml--> <view> <!-- 輪播圖 --> <swiper class="swiper" indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" circular="{{circular}}"> <block wx:for="{{imgUrls}}" wx:key="id"> <swiper-item> <image src="{{item}}" class="slide-image" /> </swiper-item> </block> </swiper> <!-- 自定義輪播圖 --> <view class="swiper-container"> <swiper circular="true" autoplay="auto" interval="5000" duration="500" current="{{swiperCurrent}}" bindchange="swiperChange" class="swiper"> <block wx:for="{{slider}}" wx:key="unique"> <swiper-item data-id="{{item.id}}" data-url="{{item.linkUrl}}"> <image src="{{item.picUrl}}" class="img"></image> </swiper-item> </block> </swiper> <view class="dots"> <block wx:for="{{slider}}" wx:key="unique"> <view class="dot{{index == swiperCurrent ? ' active' : ''}}" bindtap="chuangEvent" id="{{index}}">{{index+1}}</view> </block> </view> </view> </view>
3.樣式
mine.wxss
/* pages/mine/mine.wxss */ /**輪播圖 start**/ .swiper { height: 400rpx; width: 100%; } .swiper image { height: 100%; width: 100%; } /**輪播圖 end**/ /**自定義輪播圖 start**/ .swiper-container{ position: relative; } .swiper-container .swiper{ height: 400rpx; } .swiper-container .swiper .img{ width: 100%; height: 100%; } .swiper-container .dots{ position: absolute; right: 40rpx; bottom: 20rpx; display: flex; justify-content: center; } .swiper-container .dots .dot{ margin: 0 10rpx; width: 28rpx; height: 28rpx; background: #fff; border-radius: 50%; transition: all .6s; font: 300 18rpx/28rpx "microsoft yahei"; text-align: center; } .swiper-container .dots .dot.active{ background: #f80; color:#fff; } /**自定義輪播圖 end**/
4.效果圖
5.參數(shù)
更多關(guān)于輪播圖效果的專題,請(qǐng)點(diǎn)擊下方鏈接查看學(xué)習(xí)
javascript圖片輪播效果匯總
jquery圖片輪播效果匯總
Bootstrap輪播特效匯總
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。