尝试这个简单,具体的功能:
function resizeElementHeight(element) {
var height = 0;
var body = window.document.body;
if (window.innerHeight) {
height = window.innerHeight;
} else if (body.parentElement.clientHeight) {
height = body.parentElement.clientHeight;
} else if (body && body.clientHeight) {
height = body.clientHeight;
}
element.style.height = ((height - element.offsetTop) + "px");
}
它不取决于当前距离身体顶部的距离(如果您的300px更改)。
编辑:顺便说一下,每当用户更改浏览器的大小时,您都希望在该div上调用此功能,因此当然需要连接事件处理程序。