溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

微信小程序如何自定義可滑動(dòng)頂部TabBar選項(xiàng)卡實(shí)現(xiàn)頁(yè)面切換功能

發(fā)布時(shí)間:2021-07-09 14:53:18 來(lái)源:億速云 閱讀:196 作者:小新 欄目:web開發(fā)

這篇文章主要介紹微信小程序如何自定義可滑動(dòng)頂部TabBar選項(xiàng)卡實(shí)現(xiàn)頁(yè)面切換功能,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

具體如下:

微信小程序如何自定義可滑動(dòng)頂部TabBar選項(xiàng)卡實(shí)現(xiàn)頁(yè)面切換功能

頂部滾動(dòng)選項(xiàng)卡

話不多說(shuō),直接上代碼

pages/home/home.wxml

<scroll-view scroll-x="true" style='width: 100%; white-space:nowrap; '>
<!-- tab -->
<view class="tab">
<view class="tab-nav" style='font-size:12px'>
<view wx:for="{{tabnav.tabitem}}" bindtap="setTab" data-tabindex="{{index}}" >{{item.text}}</view>
<view>
<view class="tab-line" ></view>
</view>
</view>
</view>
</scroll-view>
<swiper current="{{currentTab}}" class="swiper-box" duration="300"  bindchange="bindChange">
<swiper-item>
<view>分類1</view>
</swiper-item>
<swiper-item>
<view>分類2</view>
</swiper-item>
<swiper-item>
<view>分類3</view>
</swiper-item>
<swiper-item>
<view>分類4</view>
</swiper-item>
<swiper-item>
<view>分類5</view>
</swiper-item>
<swiper-item>
<view>分類6</view>
</swiper-item>
</swiper>

pages/home/home.wxss

.tab {
display: flex;
flex-direction: column;
}
.tab-nav {
border-bottom: 1rpx solid #ddd;
width: 100%;
height: 80rpx;
display: flex;
line-height: 79rpx;
position: relative;
}
.tab-line {
position: absolute;
left: 0;
bottom: -1rpx;
height: 4rpx;
background: #f7982a;
transition: all 0.3s;
}
.tab-content {
flex: 1;
overflow-y: auto;
overflow-x: hidden;
}
/*選項(xiàng)卡頁(yè)面聯(lián)動(dòng)切換*/
.swiper-tab {
width: 100%;
border-bottom: 2rpx solid #777;
text-align: center;
line-height: 80rpx;
}
.swiper-tab-list {
font-size: 30rpx;
display: inline-block;
width: 33.33%;
color: #777;
}
.on {
color: #da7c0c;
border-bottom: 1rpx solid #da7c0c;
}
.swiper-box {
display: block;
height: 100%;
width: 100%;
overflow: hidden;
}
.swiper-box view {
text-align: center;
}

pages/home/home.js

Page({
data: {
showtab: 0, //頂部選項(xiàng)卡索引
tabnav: {
tabnum: 5,
tabitem: [
{
"id": 0,
"text": "分類1"
},
{
"id": 1,
"text": "分類2"
},
{
"id": 2,
"text": "分類3"
},
{
"id": 3,
"text": "分類4"
},
{
"id": 4,
"text": "分類5"
},
{
"id": 5,
"text": "分類6"
}
]
},
productList: [],
// tab切換
currentTab: 0,
},
onLoad: function () {
},
setTab: function (e) {
var that = this
that.setData({
showtab: e.currentTarget.dataset.tabindex
})
if (this.data.currentTab === e.currentTarget.dataset.tabindex) {
return false;
} else {
that.setData({
currentTab: e.currentTarget.dataset.tabindex
})
}
},
/**
* 滑動(dòng)切換tab
*/
bindChange: function (e) {
var that = this;
that.setData({ currentTab: e.detail.current,
showtab: e.detail.current});
}
})

以上是“微信小程序如何自定義可滑動(dòng)頂部TabBar選項(xiàng)卡實(shí)現(xiàn)頁(yè)面切換功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問(wèn)一下細(xì)節(jié)

免責(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)容。

AI