uniapp獲取底部安全距離以及狀態(tài)欄高度等
工作中我們常常需要設(shè)置一些特定樣式:
- 固定底部按鈕
- 自定義頂部導(dǎo)航欄
- ……
固定底部按鈕
這里需要注意的是,真機運行時底部時IOS是存在安全距離的,這個時候就需要我們處理一下
.u-fixed-b { position: fixed; bottom: 0; left: 0; right: 0; padding: 24rpx; padding-bottom: calc(24rpx + constant(safe-area-inset-bottom)); padding-bottom: calc(24rpx + env(safe-area-inset-bottom)); z-index: 50; }
- 獲取上安全距離: env(safe-area-inset-top)
- 獲取左安全距離:env(safe-area-inset-left)
- 獲取右安全距離:env(safe-area-inset-right)
- 獲取下安全距離:env(safe-area-inset-bottom)
可以在固定底部的盒子加下內(nèi)下邊距 padding-bottom: env(safe-area-inset-bottom) 避免元素被遮擋
自定義頂部導(dǎo)航欄
自定義導(dǎo)航欄需要注意的是:頂部存在狀態(tài)欄,也就是顯示信號、時間等信息的狀態(tài)欄;
<template> <view class="container"> <!-- 自定義頂部導(dǎo)航 --> <uni-nav-bar left-icon="left" backgroundColor="#FFFFFF" title="頂部導(dǎo)航" @clickLeft="backPage"></uni-nav-bar> <!-- 頁面內(nèi)容 --> <view class="page-content"> <!-- ---------- --> </view> </view> </template>
.container { background-color: #ffffff; height: 100%; padding-top: var(--status-bar-height); display: flex; flex-direction: column; position: absolute; top: 0; bottom: 0; left: 0; right: 0; }
獲取狀態(tài)欄高度:var(–status-bar-height)
可以在頁面的最外層的盒子加內(nèi)上邊距 padding-top: var(–status-bar-height)避免頂部導(dǎo)航欄與狀態(tài)欄重疊;并且需要給最外層盒子設(shè)置背景色與頁面背景色一致,不然會出現(xiàn)狀態(tài)欄的背景色和頁面背景色不一致的情況;
其他
另外uniapp 還有一些其他的css 變量(詳情查看官方文檔):
- 內(nèi)容區(qū)域距離頂部的距離:var(–window-top);
- 內(nèi)容區(qū)域距離底部的距離:var(–window-bottom);
總結(jié)
到此這篇關(guān)于uniapp獲取底部安全距離以及狀態(tài)欄高度等的文章就介紹到這了,更多相關(guān)uniapp獲取底部安全距離內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Bootstrap Table服務(wù)器分頁與在線編輯應(yīng)用總結(jié)
這篇文章主要介紹了Bootstrap Table服務(wù)器分頁與在線編輯應(yīng)用總結(jié) 的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-08-08