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

时间:2016-08-10 14:42:23   收藏:0   阅读:1188

第一种方法:

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;

}


原文:http://8432499.blog.51cto.com/8422499/1836384

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!