您的位置:首页 > 移动开发

解决键盘弹出时,webview被挤压导致背景图片被挤压出空白

2016-08-10 09:28 726 查看
第一种方法:

1、给外层div容器设置背景图片
style="height: 100%;background: url(../../images/10.jpg);background-size: 100% 100%;"
2、监听键盘弹出事件,弹出时调整容器的高度以适应背景图片

<body onresize="windowSizeChange();">
var oglHeight = document.querySelector("body").offsetHeight;
var windowSizeChange = function() { //弹出键盘时调整页面的高度,防止背景图片被挤压出空白区域
var tempHeight = document.querySelector("body").offsetHeight;
if(tempHeight == oglHeight) {
console.info("屏幕键盘隐藏");
document.getElementById('content').style.height = "100%";
} else {
console.info("键盘显示");
document.getElementById('content').style.height = "390px";
}
};

第二种方法:
背景固定,使用:before

body:before {
content: "";
position: fixed;
z-index: -1;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: url(../../images/10.jpg) center 0 no-repeat;
background-size: cover;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息