微信小程序?qū)崿F(xiàn)輪播圖指示器
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)輪播圖指示器的具體代碼,供大家參考,具體內(nèi)容如下
1.文件目錄

2.輪播圖頁(yè)面布局
需求:自定義輪播指示器:當(dāng)輪播圖發(fā)生變化時(shí),自定義輪播指示器跟隨圖片發(fā)生對(duì)應(yīng)改變
bindchange:current 改變時(shí)會(huì)觸發(fā) change 事件,即當(dāng)圖片索引發(fā)生變化時(shí)觸發(fā)的事件
current:當(dāng)前所在滑塊的 index (number類型)
autoplay: 是否自動(dòng)切換
interval: 自動(dòng)切換時(shí)間間隔
circular: 是否采用銜接滑動(dòng)
<view class="swiper">
<!-- bindchange:current 改變時(shí)會(huì)觸發(fā) change 事件-->
? <swiper bindchange="change" autoplay interval="{{1500}}" circular>
? ? <swiper-item wx:key="*this" wx:for="{{banners}}">
? ? ? <image src="{{item}}" style="height: 150px;" />
? ? </swiper-item>
? </swiper>
? <!-- 輪播圖指示器 -->
? <view class="dot">
? <!--?
? ? index:小圓點(diǎn)的索引
? ? current:圖片的索引
? ?-->
? ? <text wx:key="this" wx:for="{{4}}" ?class="{{index===current?'active':''}}"></text>
? </view>
</view>3.輪播圖樣式文件
.swiper {
? position: relative;
}
?
.dot {
? display: flex;
? justify-content: center;
? position: absolute;
? width: 100%;
? height: 25rpx;
? bottom: 20rpx;
}
?
.dot text {
? width: 80rpx;
? height: 25rpx;
? border-radius: 20rpx;
? background: peachpuff;
? margin-right: 10rpx;
}
?
/* 小圓點(diǎn)高亮顯示 */
.dot text.active{
? background: red;
}4.輪播圖邏輯實(shí)現(xiàn)
Page({
?
? /**
? ?* 頁(yè)面的初始數(shù)據(jù)
? ?*/
? data: {
? ? // 用于記錄小圓點(diǎn)的索引
? ? current:0,
? ? // 輪播圖數(shù)據(jù)
? ? banners: [
? ? ? '../../assets/banners/01.jpg',
? ? ? '../../assets/banners/02.jpg',
? ? ? '../../assets/banners/03.jpg',
? ? ? '../../assets/banners/04.jpg'
? ? ]
? },
?
? // 圖片切換處理事件
? change(e) {
? ? // e.detail.current:小圓點(diǎn)的索引
? ? // 更新數(shù)據(jù)
? ? this.setData({current:e.detail.current});
? }?
})5.實(shí)現(xiàn)效果

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript求解最長(zhǎng)回文子串的方法分享
這篇文章主要為大家介紹了JavaScript求解最長(zhǎng)回文子串的幾種方法,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-08-08
jquery的$getjson調(diào)用并獲取遠(yuǎn)程的JSON字符串問(wèn)題
jQuery中常用getJSON來(lái)調(diào)用并獲取遠(yuǎn)程的JSON字符串,將其轉(zhuǎn)換為JSON對(duì)象,如果成功,則執(zhí)行回調(diào)函數(shù),本文將詳細(xì)介紹,需要的朋友可以參考下2012-12-12
聊聊Javascript中try catch的2個(gè)作用
try...catch 可以測(cè)試代碼中的錯(cuò)誤,try 部分包含需要運(yùn)行的代碼,而catch部分包含錯(cuò)誤發(fā)生時(shí)運(yùn)行的代碼,這篇文章主要給大家介紹了關(guān)于Javascript中try catch的2個(gè)作用,需要的朋友可以參考下2021-09-09
CKEditor擴(kuò)展插件:自動(dòng)排版功能autoformat插件實(shí)現(xiàn)方法詳解
這篇文章主要介紹了CKEditor擴(kuò)展插件:自動(dòng)排版功能autoformat插件實(shí)現(xiàn)方法,結(jié)合實(shí)例形式詳細(xì)分析了CKEditor擴(kuò)展插件實(shí)現(xiàn)自動(dòng)排版功能的autoformat插件具體定義、配置與使用技巧,需要的朋友可以參考下2020-02-02

