码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2016-08-10 14:44:24      阅读:982      评论:0      收藏:0      [点我收藏+]

标签:background   content   function   背景图片   images   

第一种方法:

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;

}


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

标签:background   content   function   背景图片   images   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!