本文實例為大家分享了微信小程序圖片輪播組件的具體代碼,供大家參考,具體內容如下
先上效果圖:
wxml
<scroll-view scroll-y="true" style="height:200px" class="page-body" bindscrolltolower="loadMore"> <view class="swiper"> <swiper class="swiper-box" indicator-dots="{{indicatorDots}}" vertical="{{vertical}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" indicator-color="#fff" indicator-active-color="red"> <block wx:for-items="{{banner_url}}" wx:key="item.id"> <navigator url="../blogList/blogList"> <swiper-item> <block wx:if="{{item}}"> <image class="imgw" src="{{item.url}}" mode="aspectFill"/> </block> <block wx:else> <image src="../../images/default_pic.png" mode="aspectFill"></image> </block> </swiper-item> </navigator> </block> </swiper> </view> </scroll-view>
wxss
.imgw{width:100%;}
js
/** *頁面的初始數據 */ data: { banner_url: data.bannerList(), open: false, indicatorDots: true,//是否顯示面板指示點 autoplay: true,//是否開啟自動切換 interval: 3000,//自動切換時間間隔 duration: 500//滑動動畫時長 }
最終效果:
總結:
1. scroll-view組件的作用是可以觸發觸摸滑動
2. swiper組件的作用是制作圖片自動切換,形成輪播
3. navigator組件的作用是給每個圖片添加鏈接
主要是scroll-view和swiper兩個組件制作成可滑動的輪播組件。
DEMO下載
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com