h5 沉浸式状态栏

1. manifest.json的plus节点里面配置

"plus": {
        "statusbar": {"immersed": true},

 

2.代码里面设置plusReady或者onload方法里面

window.onload=function(){
    var immersed = 0;
    var ms=(/Html5Plus\/.+\s\(.*(Immersed\/(\d+\.?\d*).*)\)/gi).exec(navigator.userAgent);
    if(ms&&ms.length>=3){ // 当前环境为沉浸式状态栏模式
        immersed=parseFloat(ms[2]);// 获取状态栏的高度
    }
    var t=document.getElementsByTagName("header")[0]
    t.style.paddingTop=immersed+'px';
    t.style.height=immersed+44+'px';
}

 

posted @ 2018-07-13 16:40  Charlie098765  阅读(2828)  评论(0编辑  收藏  举报