第一种方法:

1、给外层div容器设置背景图片

style="height: 100%;background: url(../../p_w_picpaths/10.jpg);background-size: 100% 100%;"

2、监听键盘弹出事件,弹出时调整容器的高度以适应背景图片

<body οnresize="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(../../p_w_picpaths/10.jpg) center 0 no-repeat;

background-size: cover;

}