您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)小程序中怎么實(shí)現(xiàn)頂部tab切換以及滑動(dòng)切換時(shí)導(dǎo)航欄會(huì)隨著移動(dòng)的效果的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。
實(shí)現(xiàn)的效果:
js:
Page({ data: { // tab切換 currentTab: 0, }, swichNav: function (e) { console.log(e); var that = this; if (this.data.currentTab === e.target.dataset.current) { return false; } else { that.setData({ currentTab: e.target.dataset.current, }) } }, swiperChange: function (e) { console.log(e); this.setData({ currentTab: e.detail.current, }) }, onLoad: function (options) { // 生命周期函數(shù)--監(jiān)聽頁面加載 }, onReady: function () { // 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成 }, onShow: function () { // 生命周期函數(shù)--監(jiān)聽頁面顯示 }, onHide: function () { // 生命周期函數(shù)--監(jiān)聽頁面隱藏 }, onUnload: function () { // 生命周期函數(shù)--監(jiān)聽頁面卸載 }, onPullDownRefresh: function () { // 頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動(dòng)作 }, onReachBottom: function () { // 頁面上拉觸底事件的處理函數(shù) }, onShareAppMessage: function () { // 用戶點(diǎn)擊右上角分享 return { title: 'title', // 分享標(biāo)題 desc: 'desc', // 分享描述 path: 'path' // 分享路徑 } } })
wxml:
<view class="page"> <!--頂部導(dǎo)航欄--> <view class="swiper-tab"> <view class="tab-item {{currentTab==0 ? 'on' : ''}}" data-current="0" bindtap="swichNav">Tab1</view> <view class="tab-item {{currentTab==1 ? 'on' : ''}}" data-current="1" bindtap="swichNav">Tab2</view> <view class="tab-item {{currentTab==2 ? 'on' : ''}}" data-current="2" bindtap="swichNav">Tab3</view> </view> <!--內(nèi)容主體--> <swiper class="swiper" current="{{currentTab}}" duration="200" bindchange="swiperChange"> <swiper-item> <view>我是tab1</view> </swiper-item> <swiper-item> <view>我是tab2</view> </swiper-item> <swiper-item> <view>我是tab3</view> </swiper-item> </swiper> </view>
wxss:
.page { margin-left: 10rpx; margin-right: 10rpx; } .swiper-tab { display: flex; flex-direction: row; line-height: 80rpx; border-bottom: 2rpx solid #777; } .tab-item { width: 33.3%; text-align: center; font-size: 15px; color: #777; } .swiper { height: 1100px; background: #dfdfdf; } .on { color: blue; border-bottom: 5rpx solid blue; }
感謝各位的閱讀!關(guān)于“小程序中怎么實(shí)現(xiàn)頂部tab切換以及滑動(dòng)切換時(shí)導(dǎo)航欄會(huì)隨著移動(dòng)的效果”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
免責(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)容。