微信小程序?qū)崿F(xiàn)Swiper輪播圖效果
本文實(shí)例為大家分享了微信小程序輪播圖的具體代碼,供大家參考,具體內(nèi)容如下
1.邏輯層
mine.js
// pages/mine/mine.js
Page({
/**
* 頁面的初始數(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, // 是否自動切換
interval: 5000, // 自動切換時(shí)間間隔
duration: 500, // 滑動動畫時(shí)長
circular: true, // 是否采用銜接滑動
/*自定義輪播圖 配置*/
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)聽頁面加載
*/
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.頁面布局
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)于輪播圖效果的專題,請點(diǎn)擊下方鏈接查看學(xué)習(xí)
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript中使用document.write向頁面輸出內(nèi)容實(shí)例
這篇文章主要介紹了JavaScript中使用document.write向頁面輸出內(nèi)容實(shí)例,本文講解了輸出普通文字、帶HTML標(biāo)簽內(nèi)容的方法,需要的朋友可以參考下2014-10-10
JS實(shí)現(xiàn)css hover操作的方法示例
這篇文章主要介紹了JS實(shí)現(xiàn)css hover操作的方法,涉及javascript事件響應(yīng)及頁面元素css屬性動態(tài)操作相關(guān)技巧,需要的朋友可以參考下2017-04-04
javascript文本框內(nèi)輸入文字倒計(jì)數(shù)的方法
這篇文章主要介紹了javascript文本框內(nèi)輸入文字倒計(jì)數(shù)的方法,涉及javascript針對鍵盤事件的操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-02-02
js 獲取當(dāng)前web應(yīng)用的上下文路徑實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄猨s 獲取當(dāng)前web應(yīng)用的上下文路徑實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-08-08
微信小程序以7天為周期連續(xù)簽到7天功能效果的示例代碼
這篇文章主要介紹了微信小程序以7天為周期連續(xù)簽到7天功能效果的示例代碼,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-08-08

