admin管理员组文章数量:1323335
I need to get the height of the entire available space in the web browser, so I can position a div
halfway down the screen and stretching it all the way down.
I thought document.body.clientHeight
would work, but that returned the amount of space that was being taken up, not total available space.
I also tried making a "wrapper" div
around everything:
<div id="wrapper" style="height: 100%; width: 100%;">
//my other code
</div>
And getting the height of that, but that still returns taken up space.
How can I get the total available space in the web browser with Javascript or jQuery?
I need to get the height of the entire available space in the web browser, so I can position a div
halfway down the screen and stretching it all the way down.
I thought document.body.clientHeight
would work, but that returned the amount of space that was being taken up, not total available space.
I also tried making a "wrapper" div
around everything:
<div id="wrapper" style="height: 100%; width: 100%;">
//my other code
</div>
And getting the height of that, but that still returns taken up space.
How can I get the total available space in the web browser with Javascript or jQuery?
Share Improve this question edited Feb 13, 2013 at 14:01 Marcel Korpel 21.8k6 gold badges62 silver badges80 bronze badges asked Feb 13, 2013 at 13:57 tckmntckmn 59.4k27 gold badges118 silver badges156 bronze badges5 Answers
Reset to default 5From the jQuery docs height()
This method is also able to find the height of the window and document.
$(window).height(); // returns height of browser viewport
$(document).height(); // returns height of HTML document
I you mean the space available in parent of the element, You can try this...
var entireHeight=$('#elementID').parent().height();
var siblingHeight=0;
var elementSiblings=$('#elementID').siblings();
$.each(elementSiblings, function() {
siblingHeight= siblingHeight+$(this).height();
});
Subtracting the values i.e.
(entireHeight-siblingHeight)
should give you the available space.
Hope it helps.. :) Tell me If it aint working.
it is very simple
var max_height=screen.availHeight - (window.outerHight - window.innerHight)
A simple example with jquery
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
A2CARE 2.0
</title>
<script type="text/javascript" language="Javascript" src="jslib/jquery.js"></script>
<script type="text/javascript">
function getheight(){
var d= document.documentElement;
var b= document.body;
var who= d.offsetHeight? d: b ;
return who.clientHeight;
}
$(document).ready(function() {
var h = getheight();
document.getElementById('tryme').style.height= h + 'px';
});
</script>
</head>
<body>
<div id="tryme" style="border: 2px solid red;">
try me!
</div>
</body>
you can directly use in javascript
screen.width
screen.height
u can assign like
document.getElementById("parentId").style.width = (screen.width - 100)+"px";
document.getElementById("parentId").style.height = (screen.height-300)+"px";
本文标签: javascriptHow to get height of the entire available spaceStack Overflow
版权声明:本文标题:javascript - How to get height of the entire available space? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742136441a2422392.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论