微信小程序?qū)崿F(xiàn)輪播圖指示器
本文實例為大家分享了微信小程序?qū)崿F(xiàn)輪播圖指示器的具體代碼,供大家參考,具體內(nèi)容如下
1.文件目錄
2.輪播圖頁面布局
需求:自定義輪播指示器:當輪播圖發(fā)生變化時,自定義輪播指示器跟隨圖片發(fā)生對應(yīng)改變
bindchange:current 改變時會觸發(fā) change 事件,即當圖片索引發(fā)生變化時觸發(fā)的事件
current:當前所在滑塊的 index (number類型)
autoplay: 是否自動切換
interval: 自動切換時間間隔
circular: 是否采用銜接滑動
<view class="swiper"> <!-- bindchange:current 改變時會觸發(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:小圓點的索引 ? ? 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; } ? /* 小圓點高亮顯示 */ .dot text.active{ ? background: red; }
4.輪播圖邏輯實現(xiàn)
Page({ ? ? /** ? ?* 頁面的初始數(shù)據(jù) ? ?*/ ? data: { ? ? // 用于記錄小圓點的索引 ? ? 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:小圓點的索引 ? ? // 更新數(shù)據(jù) ? ? this.setData({current:e.detail.current}); ? }? })
5.實現(xiàn)效果
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
jquery的$getjson調(diào)用并獲取遠程的JSON字符串問題
jQuery中常用getJSON來調(diào)用并獲取遠程的JSON字符串,將其轉(zhuǎn)換為JSON對象,如果成功,則執(zhí)行回調(diào)函數(shù),本文將詳細介紹,需要的朋友可以參考下2012-12-12CKEditor擴展插件:自動排版功能autoformat插件實現(xiàn)方法詳解
這篇文章主要介紹了CKEditor擴展插件:自動排版功能autoformat插件實現(xiàn)方法,結(jié)合實例形式詳細分析了CKEditor擴展插件實現(xiàn)自動排版功能的autoformat插件具體定義、配置與使用技巧,需要的朋友可以參考下2020-02-02