微信小程序之swiper滑動面板用法示例
本文實例講述了微信小程序之swiper滑動面板用法。分享給大家供大家參考,具體如下:
swiper就是為了以后做輪播圖用的。下面是一些它的屬性
PS:關(guān)于微信小程序組件可參考本站在線工具微信小程序組件說明表http://tools.jb51.net/table/wx_component
或官網(wǎng)https://developers.weixin.qq.com/miniprogram/dev/component/
1.首先新建一個page(記得在app.json中注冊),上效果圖。
2.index.wxml中的代碼
<swiper class="view-item" indicator-dots="true" autoplay="true"> <swiper-item class="bg-green"> <view >Content</view> </swiper-item> <swiper-item class="bg-yellow"> <view >Content</view> </swiper-item> <swiper-item class="bg-blue"> <view >Content</view> </swiper-item> </swiper>
注意:在swiper標(biāo)簽中只可放置swiper-item組件,其他標(biāo)簽如果不放在swiper-item的標(biāo)簽下是沒用的,會被自動屏蔽
注意:要想實現(xiàn)滑動面板,必須有swiper和swiper-item這兩個標(biāo)簽,一個是控制整個輪播的大小和樣式。而swiper-item控制子視圖。
indicator-dots=”true”
—就是那三個小點(diǎn),顯示是true隱藏是false
autoplay=”true”
—是否自動播放。
current=“2”
—首先顯示的是第(i-1)個視圖,i-1是因為它和數(shù)組一樣,是從0開頭的。
interval=”1000”
—是指隔幾秒換一個圖片,1000是1秒
duration=”3000”
—是指從一個頁面滑動另一個頁面所需要的時間,但我發(fā)現(xiàn)一個有趣的現(xiàn)象,如果你interval=”1000”的話,它一個頁面還沒滑動完就,想滑動到第三個頁面。
3.官方提供的代碼 有意思的是它居然沒效果,剛開始我還以為自己哪里錯了,最后才發(fā)現(xiàn)官方吧swiper寫成swpier,開來微信小程序還待完善啊。先上效果圖
index.wxml中
<swpier indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}"> <block wx:for-items="{{imgUrls}}"> <swpier-item> <image src="{{item}}" class="slide-image" width="355" height="150"/> </swpier-item> </block> </swpier> <button bindtap="changeIndicatorDots"> indicator-dots </button> <button bindtap="changeAutoplay"> autoplay </button> <slider bindchange="intervalChange" show-value min="500" max="2000"/> interval <slider bindchange="durationChange" show-value min="1000" max="10000"/> duration
index.js
Page({ 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: false, autoplay: false, interval: 5000, duration: 1000 }, changeIndicatorDots: function(e) { this.setData({ indicatorDots: !this.data.indicatorDots }) }, changeAutoplay: function(e) { this.setData({ autoplay: !this.data.autoplay }) }, intervalChange: function(e) { this.setData({ interval: e.detail.value }) }, durationChange: function(e) { this.setData({ duration: e.detail.value }) } })
其實,你應(yīng)該也發(fā)現(xiàn)了,微信小程序的index.wxml和index.wxss文件很好理解并且很好上手,難點(diǎn)就在于index.js和index.json的理解,也就是對程序邏輯的處理。
希望本文所述對大家微信小程序設(shè)計有所幫助。
相關(guān)文章
JS實現(xiàn)網(wǎng)頁右側(cè)帶動畫效果的伸縮窗口代碼
這篇文章主要介紹了JS實現(xiàn)網(wǎng)頁右側(cè)帶動畫效果的伸縮窗口代碼,通過JavaScript基于時間函數(shù)實現(xiàn)頁面元素樣式漸變效果,具有一定參考借鑒價值,需要的朋友可以參考下2015-10-10JavaScript實現(xiàn)沿五角星形線擺動的小圓實例詳解
這篇文章主要介紹了JavaScript實現(xiàn)沿五角星形線擺動的小圓實例詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07Bootstrap免費(fèi)字體和圖標(biāo)網(wǎng)站(值得收藏)
在這篇內(nèi)容中,我們把這套框架上的免費(fèi)字體圖標(biāo)做了個整合(當(dāng)然,以后還會不斷的更新)。大家對bootstrap免費(fèi)字體圖標(biāo)有需要的話,可以參考本教程2017-03-03JS實現(xiàn)線性表的鏈?zhǔn)奖硎痉椒ㄊ纠窘?jīng)典數(shù)據(jù)結(jié)構(gòu)】
這篇文章主要介紹了JS實現(xiàn)線性表的鏈?zhǔn)奖硎痉椒?簡單講解了線性表鏈?zhǔn)奖硎镜脑聿⒔Y(jié)合實例形式分析了js針對線性表鏈?zhǔn)奖硎镜膭?chuàng)建、插入、刪除等節(jié)點(diǎn)操作技巧,需要的朋友可以參考下2017-04-04