Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何获得整个可用空间的高度?_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何获得整个可用空间的高度?

Javascript 如何获得整个可用空间的高度?,javascript,jquery,html,Javascript,Jquery,Html,我需要在web浏览器中获得整个可用空间的高度,这样我就可以将div放置在屏幕的一半位置,并将其一直向下拉伸 我原以为document.body.clientHeight可以工作,但它返回的是占用的空间量,而不是总的可用空间 我还试着围绕所有东西制作一个“包装器”div: <div id="wrapper" style="height: 100%; width: 100%;"> //my other code </div> //我的其他代码 得到它的高度,但仍

我需要在web浏览器中获得整个可用空间的高度,这样我就可以将
div
放置在屏幕的一半位置,并将其一直向下拉伸

我原以为
document.body.clientHeight
可以工作,但它返回的是占用的空间量,而不是总的可用空间

我还试着围绕所有东西制作一个“包装器”
div

<div id="wrapper" style="height: 100%; width: 100%;">
    //my other code
</div>

//我的其他代码
得到它的高度,但仍然返回占用的空间

如何使用Javascript或jQuery获取web浏览器中的总可用空间?

来自


jquery的一个简单示例

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


A2CARE 2.0
函数getheight(){
var d=document.documentElement;
var b=document.body;
var who=d.越权?d:b;
返回who.clientHeight;
}
$(文档).ready(函数(){
var h=getheight();
document.getElementById('tryme').style.height=h+'px';
});
试试我!

您可以直接在javascript中使用

screen.width
screen.height
你可以分配类似的任务

document.getElementById("parentId").style.width = (screen.width - 100)+"px";
document.getElementById("parentId").style.height = (screen.height-300)+"px"; 

我的意思是元素父元素中的可用空间,你可以试试这个

var entireHeight=$('#elementID').parent().height();

var siblingHeight=0;

var elementSiblings=$('#elementID').siblings();

$.each(elementSiblings, function() {
    siblingHeight= siblingHeight+$(this).height();
});
减去值,即

(entireHeight-siblingHeight) 
应该给你足够的空间

希望有帮助……)告诉我它是否工作。

它很简单

var max_height=screen.availHeight-(window.outerHight-window.innerHight)可以尝试$('body').height(),但是如果页面内容不高于视口,它将小于wondow高度。没关系,
$(window.height()
可以工作。谢谢就这样让我接受吧。
var entireHeight=$('#elementID').parent().height();

var siblingHeight=0;

var elementSiblings=$('#elementID').siblings();

$.each(elementSiblings, function() {
    siblingHeight= siblingHeight+$(this).height();
});
(entireHeight-siblingHeight)