微信小程序自定義漸變的tabbar導(dǎo)航欄功能
做為自己的一個(gè)小筆記,以免后面再用到


1,在需要自定義的界面的json文件中加入下面代碼 "navigationStyle": "custom" ,隱藏系統(tǒng)導(dǎo)航欄
{
"navigationBarTitleText": "",
"navigationBarBackgroundColor": "#000",
"navigationBarTextStyle": "white",
"backgroundTextStyle": "dark",
"usingComponents": {
},
"navigationStyle": "custom"
}2,創(chuàng)建components 文件,為了方便復(fù)用
js 文件內(nèi)容:
const app = getApp()
Component({
properties: {
defaultData: {
type: Object,
value: {
title: "默認(rèn)標(biāo)題"
},
observer: function (newVal, oldVal) {}
},
topOpacity: {
type: Number,
value: {
topOpacity: 0,
}
}
},
data: {
navBarHeight: app.globalData.navBarHeight,
menuRight: app.globalData.menuRight,
menuTop: app.globalData.menuTop,
menuHeight: app.globalData.menuHeight,
},
attached: function () {
},
methods: {
}
})wxml文件內(nèi)容:
<!-- 自定義頂部欄 -->
<view class="nav-bar" style="height:{{navBarHeight}}px;">
<view class="nav-barback" style="height:{{navBarHeight}}px;opacity:{{topOpacity}}"></view>
<input class="search" placeholder="輸入關(guān)鍵詞!" style="height:{{menuHeight}}px; min-height:{{menuHeight}}px; line-height:{{menuHeight}}px; left:{{menuRight}}px; top:{{menuTop}}px;"></input>
</view>
<!-- 占位,高度與頂部欄一樣 -->
<view style="height:{{navBarHeight}}px;"></view>wxss文件內(nèi)容:
.nav-bar {
position: fixed;
width: 100%;
top: 0;
color: rgb(255, 255, 255);
/* background: rgb(255, 255, 255); */
z-index: 10000;
}
.nav-barback{
background-color: #FFD52F;
width: 100%;
position: relative;
top: 0;
z-index: 10001;
}
.nav-bar .search {
width: 60%;
color: #333;
font-size: 14px;
background: #fff;
position: absolute;
border-radius: 50px;
background: rgb(255, 255, 255);
padding-left: 14px;
z-index: 10002;
}在需要使用的界面使用方法
1,在json中引入該components,
2,wxml中
<navigationBar default-data="{{defaultData}}" topOpacity="{{topOpacityFloat}}"></navigationBar>3,js中,這個(gè)標(biāo)題看需求后面可以替換搜索欄
defaultData: {
title: "我的主頁", // 導(dǎo)航欄標(biāo)題
},4,該方法是監(jiān)聽當(dāng)前界面滾動的回調(diào),上滑時(shí),自定義的背景色透明度會從0一直到1,達(dá)成漸變效果
onPageScroll(t){
let topOpacity = t.scrollTop / 100
console.log('topOpacity',t.scrollTop,topOpacity);
if (t.scrollTop < 10) {
topOpacity = 0
} else if (topOpacity >= 1) {
topOpacity = 1
}
this.setData({
topOpacityFloat: topOpacity
})
},到此這篇關(guān)于微信小程序自定義漸變的tabbar導(dǎo)航欄的文章就介紹到這了,更多相關(guān)小程序自定義導(dǎo)航欄內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 微信小程序自定義頂部導(dǎo)航欄并適配不同機(jī)型實(shí)例詳解
- 微信小程序動態(tài)設(shè)置導(dǎo)航欄標(biāo)題的實(shí)現(xiàn)步驟
- 小程序自定義tabbar導(dǎo)航欄及動態(tài)控制tabbar功能實(shí)現(xiàn)方法(uniapp)
- 微信小程序使用uni-app實(shí)現(xiàn)首頁搜索框?qū)Ш綑诠δ茉斀?/a>
- uniapp小程序配置tabbar底部導(dǎo)航欄實(shí)戰(zhàn)指南
- uniapp開發(fā)微信小程序自定義頂部導(dǎo)航欄功能實(shí)例
- 微信小程序?qū)崿F(xiàn)側(cè)邊導(dǎo)航欄
- uniapp微信小程序自定義導(dǎo)航欄的全過程
- 微信小程序?qū)崿F(xiàn)自定義導(dǎo)航欄
- 微信小程序自定義導(dǎo)航欄功能的實(shí)現(xiàn)
相關(guān)文章
JavaScript使用prototype屬性實(shí)現(xiàn)繼承操作示例
這篇文章主要介紹了JavaScript使用prototype屬性實(shí)現(xiàn)繼承操作,結(jié)合實(shí)例形式詳細(xì)分析了JavaScript使用prototype屬性實(shí)現(xiàn)繼承的相關(guān)原理、實(shí)現(xiàn)方法與操作注意事項(xiàng),需要的朋友可以參考下2020-05-05
JS實(shí)現(xiàn)懸浮球只在一側(cè)滑動并且是橫屏狀態(tài)下
這篇文章主要介紹了JS實(shí)現(xiàn)懸浮球只在一側(cè)滑動 并且是橫屏狀態(tài)下,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-08-08
Javascript中Promise的四種常用方法總結(jié)
這篇文章主要給大家總結(jié)介紹了關(guān)于Javascript中Promise的四種常用方法,分別是處理異步回調(diào)、多個(gè)異步函數(shù)同步處理、異步依賴異步回調(diào)和封裝統(tǒng)一的入口辦法或者錯(cuò)誤處理,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。2017-07-07
如何用threejs實(shí)現(xiàn)實(shí)時(shí)多邊形折射
這篇文章主要介紹了如何用threejs實(shí)現(xiàn)實(shí)時(shí)多邊形折射,對three.js庫感興趣的同學(xué),可以參考下2021-05-05

