您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)微信小程序中如何實(shí)現(xiàn)分頁滑動(dòng)欄,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
功能:
1.分頁欄與滑動(dòng)視圖綁定
2.點(diǎn)擊分頁欄自動(dòng)滑動(dòng)到對(duì)應(yīng)視圖
3.滑動(dòng)的到視圖對(duì)應(yīng)分頁欄自動(dòng)顯示選中樣式
上代碼
wxml
<view class="tapNav"> <view class="pw_tabArr.tabCurrentIndex==0?'active':''" data-index="0" bindtap="veHandle">分頁標(biāo)簽1</view> <view class="pw_tabArr.tabCurrentIndex==1?'active':''" data-index="1" bindtap="veHandle">分頁標(biāo)簽2</view> <view class="pw_tabArr.tabCurrentIndex==2?'active':''" data-index="2" bindtap="veHandle">分頁標(biāo)簽3</view> </view> <swiper id="swiper" indicator-dots="pw_indicatorDots" autoplay="pw_autoplay" interval="pw_interval" duration="pw_duration" current="pw_current" bindchange="swiperChange"> <block wx:for="pw_imgUrls"> <swiper-item id="swiper-item"> <image id="imgae" src="pw_item" class="slide-image" width="355" height="150"/> </swiper-item> </block>
</swiper>
wxss
/* 1.橫向排列分頁標(biāo)簽 2.每個(gè)分頁標(biāo)簽各占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 //獲取應(yīng)用實(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í)長(zhǎng) duration: 1000, //存放滑動(dòng)視圖的current current:0, //分頁標(biāo)簽class條件判斷的值 tabArr:{ tabCurrentIndex:0 } }, //事件處理函數(shù) //觸摸分頁標(biāo)簽觸發(fā)事件 veHandle:function(e){ //每個(gè)分頁標(biāo)簽都設(shè)置了data-index,觸摸觸發(fā)事件獲取此數(shù)值 //用此數(shù)值替換滑動(dòng)視圖的current //用此數(shù)值替換分頁標(biāo)簽class判斷的值 console.log(e.target.dataset.index) var currentIndex = e.target.dataset.index this.setData({ current:currentIndex, "tabArr.tabCurrentIndex":currentIndex }) }, //通過滑塊視圖的current改變觸發(fā)事件 swiperChange:function(e){ //獲取視圖滑塊當(dāng)前的current //用此數(shù)值替換分頁標(biāo)簽的current的值 console.log(e.detail.current) var swiperCurrent = e.detail.current; this.setData({ 'tabArr.tabCurrentIndex':swiperCurrent }) }, onLoad: function () { console.log('onLoad') } })
關(guān)于“微信小程序中如何實(shí)現(xiàn)分頁滑動(dòng)欄”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。