微信小程序?qū)崿F(xiàn)Swiper輪播圖效果
本文實(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)聽頁(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í)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JS使用 cryptojs加密解密(對(duì)稱加密庫(kù))的問(wèn)題
js 加密解密可以使用 crypto-js,這是一個(gè)對(duì)稱加密的庫(kù), 可以使用 AES DES 但沒有 rsa 等非對(duì)稱加密的方法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧2023-11-11
教學(xué)演示-UBB,剪貼板,textRange及其他
[紅色]教學(xué)演示-UBB,剪貼板,textRange及其他...2006-11-11
JS表示Stack類練習(xí)用棧實(shí)現(xiàn)任意進(jìn)制轉(zhuǎn)換
這篇文章主要為大家介紹了JS表示Stack類練習(xí)用棧實(shí)現(xiàn)任意進(jìn)制轉(zhuǎn)換示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04
bootstrap 模態(tài)框(modal)實(shí)現(xiàn)水平垂直居中顯示
這篇文章主要為大家詳細(xì)介紹了bootstrap 模態(tài)框modal實(shí)現(xiàn)水平垂直居中顯示,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01

