- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) > web開(kāi)發(fā) >
- 微信小程序模板之分頁(yè)滑動(dòng)欄的示例分析
這篇文章給大家分享的是有關(guān)微信小程序模板之分頁(yè)滑動(dòng)欄的示例分析的內容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
具體內容如下
功能:
1.分頁(yè)欄與滑動(dòng)視圖綁定
2.點(diǎn)擊分頁(yè)欄自動(dòng)滑動(dòng)到對應視圖
3.滑動(dòng)的到視圖對應分頁(yè)欄自動(dòng)顯示選中樣式
效果圖
上代碼
wxml
<view class="tapNav"> <view class="{{tabArr.tabCurrentIndex==0?'active':''}}" data-index="0" bindtap="veHandle">分頁(yè)標簽1</view> <view class="{{tabArr.tabCurrentIndex==1?'active':''}}" data-index="1" bindtap="veHandle">分頁(yè)標簽2</view> <view class="{{tabArr.tabCurrentIndex==2?'active':''}}" data-index="2" bindtap="veHandle">分頁(yè)標簽3</view> </view> <swiper id="swiper" indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" current="{{current}}" bindchange="swiperChange"> <block wx:for="{{imgUrls}}"> <swiper-item id="swiper-item"> <image id="imgae" src="{{item}}" class="slide-image" width="355" height="150"/> </swiper-item> </block>
</swiper>
wxss
/* 1.橫向排列分頁(yè)標簽 2.每個(gè)分頁(yè)標簽各占1/3 */ .tapNav { display: flex; flex-direction: row; } .tapNav view{ flex:1; width:200rpx; height:100rpx; text-align: center; line-height: 100rpx; font-family: "微軟雅黑"; } /*選中樣式*/ .tapNav .active { color:blue; border-bottom:4rpx solid mediumseagreen; } #swiper { margin-top:40rpx; } #swiper image{ width:100%; }
js
//index.js //獲取應用實(shí)例 var app = getApp() 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' ], //是否顯示面板指示點(diǎn) indicatorDots: true, //自動(dòng)播放 autoplay: true, //切換時(shí)間間隔 interval: 2000, //滑動(dòng)時(shí)長(cháng) duration: 1000, //存放滑動(dòng)視圖的current current:0, //分頁(yè)標簽class條件判斷的值 tabArr:{ tabCurrentIndex:0 } }, //事件處理函數 //觸摸分頁(yè)標簽觸發(fā)事件 veHandle:function(e){ //每個(gè)分頁(yè)標簽都設置了data-index,觸摸觸發(fā)事件獲取此數值 //用此數值替換滑動(dòng)視圖的current //用此數值替換分頁(yè)標簽class判斷的值 console.log(e.target.dataset.index) var currentIndex = e.target.dataset.index this.setData({ current:currentIndex, "tabArr.tabCurrentIndex":currentIndex }) }, //通過(guò)滑塊視圖的current改變觸發(fā)事件 swiperChange:function(e){ //獲取視圖滑塊當前的current //用此數值替換分頁(yè)標簽的current的值 console.log(e.detail.current) var swiperCurrent = e.detail.current; this.setData({ 'tabArr.tabCurrentIndex':swiperCurrent }) }, onLoad: function () { console.log('onLoad') } })
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自互聯(lián)網(wǎng)轉載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權請聯(lián)系站長(cháng)郵箱:ts@56dr.com進(jìn)行舉報,并提供相關(guān)證據,一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容。
Copyright ? 2009-2021 56dr.com. All Rights Reserved. 特網(wǎng)科技 版權所有 珠海市特網(wǎng)科技有限公司 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2 建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站