/    Sign up×
Community /Pin to ProfileBookmark

Dynamically adjusting DIV height with Javascript

Dear all,

I’m new on this forum, and not a real Javascript expert. Maybe someone can help me. I have already been looking for a solution on this forum, but the tips I’ve found didn’t help until now.
I’m having a problem with dynamically building up a webpage.
The page consists of a DIV-tag, to center all the content on the page.
The DIV-tag consists of 3 other DIV tags, each consisting of a table.
The first one is a small header, the last one is some kind of legend, and the middle one is a big table with content in it.
Now I want the last DIV and the first DIV to be always visible on the screen, if enough screen space, and the middle one should have a dynamic height, depending on the height of the other 2 DIV’s. I ‘ve written a Javascript function, and it seems to calculate the height correctly, but the middle DIV doesn’t resize :-/

This is how the page looks:


______________

|DIV_1: header |
|_____________|
|DIV_2: content |
|_
__
__________|
|DIV_3: legend |
|_
__
__________|

Javascript code:

function pageY(elem)
{
return elem.offsetParent ? (elem.offsetTop + pageY(elem.offsetParent)) : elem.offsetTop;
}

function getDocHeight()
{
var D = document;
return Math.max(
Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
Math.max(D.body.clientHeight, D.documentElement.clientHeight)
);
}

var buffer = 20;
function resizeDiv()
{
var height = document.body.offsetHeight;
height -= pageY(document.getElementById(‘orderListDIV’))+ buffer ;

var docHeight = getDocHeight();
docHeight -= pageY(document.getElementById(‘legendDIV’))+ buffer ;

height -= docHeight;

if (height < 0)
height = 0;

document.getElementById(‘orderListDIV’).style.height = height + ‘px’;

}

The last statement doesn’t seem to work: the orderListDIV tag is not resized…

Can someone help me?

Thanks in advance!

Best regards,

Diederik

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @lolindir spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...