這篇文章給大家介紹小程序開發(fā)中如何利用Tab實現(xiàn)一個滾動選項卡,內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
具體內(nèi)容如下
最終效果如上。問題:
1、tab標(biāo)題總共8個,所以一屏無法全部顯示。
2、tab內(nèi)容區(qū)左右滑動切換時,tab標(biāo)題隨即做標(biāo)記(active)。
3、當(dāng)active的標(biāo)題不在當(dāng)前屏顯示時,要使其能顯示到當(dāng)前屏中。
一、wxml結(jié)構(gòu)
tab標(biāo)題因一排八個,所以使用 scroll-view組件,使其可橫向滾動。
tab內(nèi)容可左右滑動切換,使用swiper組件實現(xiàn)
為了偷懶,所以數(shù)據(jù)都通過wx:for遍歷重復(fù)出來。
說明:
1、設(shè)置data-current屬性用于:點擊當(dāng)前項時,通過點擊事件swichNav中處理e.dataset.current取到點擊的目標(biāo)值。
2、swiper組件的current組件用于控制當(dāng)前顯示哪一頁
3、swiper組件綁定change事件switchTab,通過e.detail.current拿到當(dāng)前頁
<view > <scroll-view scroll-x="true" class="tab-h" scroll-left="{{scrollLeft}}"> <view class="tab-item {{currentTab==0?'active':''}}" data-current="0" bindtap="swichNav">健康</view> <view class="tab-item {{currentTab==1?'active':''}}" data-current="1" bindtap="swichNav">情感</view> <view class="tab-item {{currentTab==2?'active':''}}" data-current="2" bindtap="swichNav">職場</view> <view class="tab-item {{currentTab==3?'active':''}}" data-current="3" bindtap="swichNav">育兒</view> <view class="tab-item {{currentTab==4?'active':''}}" data-current="4" bindtap="swichNav">糾紛</view> <view class="tab-item {{currentTab==5?'active':''}}" data-current="5" bindtap="swichNav">青蔥</view> <view class="tab-item {{currentTab==6?'active':''}}" data-current="6" bindtap="swichNav">全部</view> <view class="tab-item {{currentTab==7?'active':''}}" data-current="7" bindtap="swichNav">其他</view> </scroll-view> <swiper class="tab-content" current="{{currentTab}}" duration="300" bindchange="switchTab" > <swiper-item wx:for="{{[0,1,2,3,4,5,6,7]}}"> <scroll-view scroll-y="true" class="scoll-h" > <block wx:for="{{[1,2,3,4,5,6,7,8]}}" wx:key="*this"> <view class="item-ans"> <view class="avatar"> <image class="img" src="/avatar.png"></image> </view> <view class="expertInfo"> <view class="name">歡顏</view> <view class="tag">知名情感博主</view> <view class="answerHistory">134個回答,2234人聽過 </view> </view> <navigator url="/pages/askExpert/expertDetail" class="askBtn">問TA</navigator> </view> </block> </scroll-view> </swiper-item> </swiper> </view>
網(wǎng)站名稱:小程序開發(fā)中如何利用Tab實現(xiàn)一個滾動選項卡-創(chuàng)新互聯(lián)
本文來源:http://aaarwkj.com/article34/geope.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、商城網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)、ChatGPT、軟件開發(fā)、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容