最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

小程序如何實(shí)現(xiàn)中間帶加號的tabbar

 更新時間:2022年04月29日 10:44:45   作者:安小軒  
自定義tabBar可以讓開發(fā)者更加靈活地設(shè)置tabBar樣式,以滿足更多個性化的場景,下面這篇文章主要給大家介紹了關(guān)于小程序如何實(shí)現(xiàn)中間帶加號tabbar的相關(guān)資料,需要的朋友可以參考下

前言

相信大家也看過很多app或者小程序的tabbar中間是一個突出加號,這個用自帶的組件無法實(shí)現(xiàn),需要我們手動寫一個tabbar的樣式來實(shí)現(xiàn)效果。我們一起看看吧!

首先新建一個tabbar的組件。

html代碼

注意點(diǎn):需要判斷是否是iphonex系列的手機(jī),這類手機(jī)需要設(shè)置高度。對于中間的加號突出的菜單,格外設(shè)置樣式。直接使用了navigator,省去了需要寫方法跳轉(zhuǎn)這一步驟。但是需要設(shè)置hover-class="none"屬性。避免點(diǎn)擊時候有陰影出現(xiàn)。

<view class="tabbar_box {{isIphoneX ? 'iphoneX-height':''}}">
    <block wx:for="{{tabbar}}" wx:key="index">
        <navigator wx:if="{{item.isSpecial}}" hover-class="none" url="{{item.pagePath}}" class="tabbar_nav {{item.selected?'selected' : ''}}" open-type="navigate">
            <view class='special-wrapper'>+</view>
        </navigator>
        <navigator wx:else hover-class="none" url="{{item.pagePath}}" class="tabbar_nav {{item.selected?'selected' : ''}}" open-type="switchTab">
            <image class="tabbar_icon" src="{{item.selected ? item.selectedIconPath : item.iconPath}}"></image>
            <text>{{item.text}}</text>
        </navigator>
    </block>
</view>

js代碼

定義tabbar的數(shù)據(jù),包括選中圖標(biāo)和未選中圖標(biāo),路徑url和菜單文本值。

 data: {
    isIphoneX: app.globalData.systemInfo.model.search('iPhone X') != -1 ? true : false,
    tabbar: [{
        "pagePath": "/teacher/pages/teach/classroom/classroom",
        "iconPath": "/image/index.png",
        "selectedIconPath": "/image/index-active.png",
        "text": "首頁"
    },
    {
        "pagePath": "/teacher/pages/teach/publish/publish",
        "isSpecial": true,
    },
    {
        "pagePath": "/teacher/pages/teach/mine/mine",
        "iconPath": "/image/index.png",
        "selectedIconPath": "/image/index-active.png",
        "text": "我的"
    }],
}

在需要的頁面引入組件

在需要你用到tabbar的頁面引入組件

{
  "usingComponents": {
    "custom-tabbar": "../../components/common/custom-tabbar/custom-tabbar",
  }
}

適用不同頁面

可能會有不同的頁面需要展示不同tabbar的時候,可以通過傳參from,來判斷是哪個頁面引用的。從而展示不通的tabbar數(shù)據(jù)。就可以適用于其他需要tabbar的頁面。

<custom-tabbar from="classroom"></custom-tabbar>

設(shè)置tabbar選中狀態(tài)

通過判斷當(dāng)前路由和當(dāng)前tabbar數(shù)據(jù)的path,對比成功后設(shè)置selected屬性,實(shí)現(xiàn)選中效果。

setTabbar(){
    let currentPages = getCurrentPages();
    let pagePath = currentPages[currentPages.length - 1].route;
    this.data.tabbar.forEach(item => {
        item.selected = false;
        if(item.pagePath.indexOf(pagePath) > -1){
            item.selected = true;
        }
    })
    this.setData({
        tabbar: this.data.tabbar
    });
 }

css代碼

樣式文件

.tabbar_box{
    background-color: #fff;
    display: flex;
    justify-content: space-around;
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 10;
    width: 100%;
    height: 98rpx;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.1);
}

.tabbar_box.iphoneX-height{
    padding-bottom: 66rpx;
}

.middle-wrapper{
  position: absolute;
  right: 310rpx;
  bottom: 0;
  background-color: #fff;
  width: 120rpx;
  height: 120rpx;
  border-radius: 50%;
  border-top: 2rpx solid #f2f2f3;
}

.middle-wrapper.iphoneX-height{
  bottom: 66rpx;
}

.tabbar_nav{
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 20rpx;
    height: 100%;
    position: relative;
    color: rgba(0, 0, 0, 0.45);
    font-size: 24rpx;
}

.tabbar_icon{
    width: 42rpx;
    height: 42rpx;
    margin-bottom: 10rpx;
}

.special-wrapper{
  position: absolute;
  top: -30rpx;
  width: 74rpx;
  height: 74rpx;
  border-radius: 50%;
  background-color: var(--main-font-color);
  text-align: center;
  box-sizing: border-box;
  padding: 6rpx;
  font-size: 54rpx;
  line-height: 54rpx;
  color: #fff;
}

.selected {
    color: var(--main-font-color);
}

最終效果

以上就是實(shí)現(xiàn)帶加號的tabbar的全部代碼了,記錄一下,溫故而知新!

總結(jié)

到此這篇關(guān)于小程序如何實(shí)現(xiàn)中間帶加號tabbar的文章就介紹到這了,更多相關(guān)小程序加號tabbar內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

深州市| 桃江县| 西青区| 吴川市| 泉州市| 昆山市| 黑龙江省| 浠水县| 酒泉市| 万全县| 临夏市| 和林格尔县| 蒲城县| 汽车| 易门县| 阿拉尔市| 搜索| 临夏市| 新化县| 建阳市| 精河县| 屏东市| 永靖县| 江都市| 荃湾区| 绥芬河市| 枣强县| 仙桃市| 六枝特区| 惠州市| 桐庐县| 福海县| 乌兰察布市| 威远县| 仪陇县| 邢台县| 浮梁县| 南岸区| 合阳县| 荃湾区| 怀来县|