提交 5b18ce3c 编写于 作者: Q qiang

fix: 优化H5端 css 变量处理

上级 068a5bec
......@@ -73,7 +73,9 @@ export default {
hideTabBar (newVal, oldVal) {
// TODO 不支持 css 变量时
if (uni.canIUse('css.var')) {
const windowBottom = !newVal ? (TABBAR_HEIGHT + 'px') : '0px'
const windowBottomValue = !newVal ? (TABBAR_HEIGHT) : 0
const envMethod = uni.canIUse('css.env') ? 'env' : (uni.canIUse('css.constant') ? 'constant' : '')
const windowBottom = windowBottomValue && envMethod ? `calc(${windowBottomValue}px + ${envMethod}(safe-area-inset-bottom))` : `${windowBottomValue}px`
document.documentElement.style.setProperty('--window-bottom', windowBottom)
console.debug(`uni.${windowBottom ? 'showTabBar' : 'hideTabBar'}:--window-bottom=${windowBottom}`)
}
......@@ -103,7 +105,7 @@ export default {
}
</script>
<style>
<style>
@import "~uni-core/view/index.css";
uni-app {
display: block;
......
......@@ -28,8 +28,8 @@ function updateCssVar (vm) {
const windowTopValue = navigationBarType === 'default' || navigationBarType === 'float' ? NAVBAR_HEIGHT : 0
const windowBottomValue = getApp().$children[0].showTabBar ? TABBAR_HEIGHT : 0
const envMethod = uni.canIUse('css.env') ? 'env' : (uni.canIUse('css.constant') ? 'constant' : '')
const windowTop = windowTopValue && envMethod ? `calc(${windowTopValue}px + ${envMethod}(safe-area-inset-top))` : '0px'
const windowBottom = windowBottomValue && envMethod ? `calc(${windowBottomValue}px + ${envMethod}(safe-area-inset-bottom))` : '0px'
const windowTop = windowTopValue && envMethod ? `calc(${windowTopValue}px + ${envMethod}(safe-area-inset-top))` : `${windowTopValue}0px`
const windowBottom = windowBottomValue && envMethod ? `calc(${windowBottomValue}px + ${envMethod}(safe-area-inset-bottom))` : `${windowBottomValue}px`
const style = document.documentElement.style
style.setProperty('--window-top', windowTop)
style.setProperty('--window-bottom', windowBottom)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册