阿哇
阿哇
  • 发布:2018-10-21 18:38
  • 更新:2019-04-13 23:55
  • 阅读:27442

uni-app nvue沉浸式状态栏(线性渐变色)

分类:uni-app
<template>  
<div class="page-searchList">  
    <div class="header">  
        <div class="statusBar" :style="{height:statusBarHeight+'wx'}"></div><!-- 状态栏占位 -->  
        <div class="info"><text style="font-size: 16wx;">标题栏</text></div>  
    </div>  
    <div class="content">  
        <text style="font-size: 50wx;">{{statusBarHeight}}wx</text> <!-- 打印状态栏高度 -->  
    </div>  
</div>  
</template>  

<script>  
export default {  
    data: {  
        statusBarHeight: ''  
    },  
    created() {  
        let _t = this;  
        setTimeout(() => { //获取状态栏高度,setTimeout后才能调用uni.  
            uni.getSystemInfo({  
                success: function(res) {  
                    _t.statusBarHeight = res.statusBarHeight;  
                    console.log(_t.statusBarHeight);  
                }  
            });  
        }, 1);  
    }  
};  
</script>  

<style>  
.page-searchList {  
    background-color: #8f8f94;  
    justify-content: center;  
    align-items: center;  
}  
.header {  
    background-image: linear-gradient(to right, #a80077, #66ff00);  
    width: 750px;  
    position: fixed;  
    top: 0;  
}  
.info {  
    height: 44wx;  
    justify-content: center;  
    align-items: center;  
}  
</style>

17 关注 分享
DCloud_heavensoft m***@handsure.com Trust 7***@qq.com 不知 l***@163.com 05309 dawnflyingnow Neil_HL foryou SimpleJalon 2***@qq.com 9***@qq.com 泡泡嘿 sonicsunsky 冷月i 6***@qq.com

要回复文章请先登录注册

阿哇

阿哇 (作者)

回复 z***@126.com :
我用845的手机测试了一下,光获取状态栏高度就耗时140毫秒左右,肯定会闪屏
建议设置非沉浸式状态栏,然后把获取状态栏高度去掉
或者,为设置的状态栏加上高度变化过度动画,这样看上去就不是很违和
在或者,用官方h5+接口自行绘制,缺点是无法渐变色
2019-04-13 23:55
z***@126.com

z***@126.com

有一点问题,在测试手机上,首次加载页面时,状态栏没有高度,会出现闪动,这个问题怎么解决
2019-04-11 19:13
张德帅

张德帅

wx 是啥意思啊,和px是什么关系
2019-04-09 14:19
8***@qq.com

8***@qq.com

这个高度有问题,我用的你一模一样的代码,怎么效果和你的完全不一样
2019-01-23 22:59
阿哇

阿哇 (作者)

回复 JCwhy :
flex布局可以很简单的实现
2019-01-19 19:23
JCwhy

JCwhy

想问下在有返回的情况下怎么确保标题居中
2019-01-18 22:44
JCwhy

JCwhy

状态栏的字体颜色可以修改吗
2019-01-12 18:12
05309

05309

2018-11-21 19:45
1***@qq.com

1***@qq.com

好的
2018-11-16 17:46
7***@qq.com

7***@qq.com

不错 刚好用上
2018-11-16 14:50