微信小程序自定義漸變的tabbar導(dǎo)航欄功能
做為自己的一個小筆記,以免后面再用到
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中,這個標(biāo)題看需求后面可以替換搜索欄
defaultData: { title: "我的主頁", // 導(dǎo)航欄標(biāo)題 },
4,該方法是監(jiān)聽當(dāng)前界面滾動的回調(diào),上滑時,自定義的背景色透明度會從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 小型打飛機(jī)游戲?qū)崿F(xiàn)原理說明
這次為大家?guī)淼男∮螒蚴牵捍蝻w機(jī)。呃。。。我本人就寫不出什么驚天大作的游戲的了,只能寫寫小游戲,代碼量小,又可以學(xué)習(xí),主要是想法思路,代碼量大,估計也沒啥人會去研究學(xué)習(xí)。。。2010-10-10jsonp跨域及實(shí)現(xiàn)百度首頁聯(lián)想功能的方法
這篇文章主要介紹了jsonp跨域及實(shí)現(xiàn)百度首頁聯(lián)想功能的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-08-08js實(shí)現(xiàn)讓某個動作延遲幾秒執(zhí)行
這篇文章主要介紹了使用js實(shí)現(xiàn)讓某個動作延遲幾秒執(zhí)行的方法,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-06-06JS 排序輸出實(shí)現(xiàn)table行號自增前端動態(tài)生成的tr
一個項(xiàng)目,需要對數(shù)據(jù)進(jìn)行排序輸出,要求有行號,依次遞增1.2.3.4.5,使用前端動態(tài)生成的tr2014-08-08element-ui的回調(diào)函數(shù)Events的用法詳解
這篇文章主要介紹了element-ui的回調(diào)函數(shù)Events的用法,本文通過實(shí)例代碼給大家介紹了change回調(diào)函數(shù)的使用方法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-10-10javascript使用eval或者new Function進(jìn)行語法檢查
使用代碼來實(shí)現(xiàn)分析代碼的語法,這是一件極其痛苦的事情。簡單的解決辦法是:使用腳本引擎自己的語法檢查,比方說eval( ) 或者new Function( )。2010-10-10