Forum Moderators: open

Message Too Old, No Replies

How to get the height of the document?

         

zls0424

3:40 am on Jul 18, 2007 (gmt 0)

10+ Year Member



I just want a div to be as high as possible.

For example:

----------------------------------------------+
Something

My div

Something
----------------------------------------------+

Ideally, the whole content is displayed with full screen and there is no scrollbars.

I can get the top-left point of 'my div'. If I can get the height of all the elements below it, I can adjust its height to (screenheight - mytop - belowheight).

One possible way is to find the whole height of the document, without the empty spaces(if the document is only part of the screen). But I don't known how to. document.body.offsetHeight/ document.documentElement.offsetHeight seems to return the whole height of the screen while I only need part of them on IE.

Any ideas?

Trace

4:19 pm on Jul 18, 2007 (gmt 0)

10+ Year Member



I'm assuming you can't just do it via css?

<div id="1">
Something
</div>

<div id="2">
My div
</div>

<div id="3">
Something
</div>

<script type="text/javascript">
// get total height
var totalHeight = document.body.offsetHeight;
// get height of top and bottom div
var topDivHeight = document.getElementById('1').offsetHeight;
var bottomDivHeight = document.getElementById('3').offsetHeight;
// calculate height for center div and apply it
var centerDivHeight = totalHeight - topDivHeight - bottomDivHeight;
document.getElementById('2').style.height = centerDivHeight + 'px';
</script>

[edited by: Trace at 4:19 pm (utc) on July 18, 2007]

zls0424

1:53 am on Jul 19, 2007 (gmt 0)

10+ Year Member



Yeah, for my example we can do this. I wonder if there is a way to realize it even if I don't know the contents below it:)