Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Force html relayout in javascript?

Credits go to Matthew Leverton for helping out!
This thread is locked; no one can reply to it. rss feed Print
Force html relayout in javascript?
Thomas Fjellstrom
Member #476
June 2000
avatar

I have this interface I'm trying to work on, left side has a list view like widget (or will, for now its a div), and on the right side, its a "tabview" (using yui/yahoo ui).

I can expand the tabview just fine, but trying to get it to shrink back properly on resize is an issue. The way its setup a height of 100% makes the content div overflow its parent by the height of the tab bar div, the only thing I could think to do was grab the heights in js and set it all there. which works ok, for expanding the height. But since i'm just getting the clientHeight or offestHeight of the siblings and/or parents, which changes when the browser window is expanded, but wont when shrunk due to the previous "style.height" assignment.

Is there a way to make a browser re layout the html without refreshing the page? Or is there some other way I can get this to work?

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Matthew Leverton
Supreme Loser
January 1999
avatar

Without a picture, it's a bit hard to visualize. It sounds like you need to resize things via JavaScript according to the size of the browser window:

http://www.howtocreate.co.uk/tutorials/javascript/browserwindow

After resize, check the height of the browser window, and resize the widgets accordingly.

Thomas Fjellstrom
Member #476
June 2000
avatar

Alright thanks. I should have thought about it a little harder. Once I looked at it again, I saw what I was doing wrong.

Now thats not to say its perfect, it doesn't always align everything properly, but its close enough I think.

Cookies for Matthew.

edit: basically its this page: http://teachme.tomasu.org/chat/index2.php

edit2: WEIRD :o

Konqueror doesn't like the javascript I'm using, and Firefox won't respect the width I have set for the left list box thing. odd.

edit3:

Is there a way to get the margin or padding in pixel units? I've set the margin in "em". So I'm not sure how to parse that out.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Matthew Leverton
Supreme Loser
January 1999
avatar

Quote:

Is there a way to get the margin or padding in pixel units? I've set the margin in "em". So I'm not sure how to parse that out.

I always stick to pixels in such resizing scenarios to avoid that problem.

I've not ever tried this, but you might be able to make use of this.

And another thought, doesn't offsetHeight/Width give you that automatically? I assume you're trying to do something like: widgetB.y = widgetA.Height + widgetA.y (where I've obviously made up the property names).

Thomas Fjellstrom
Member #476
June 2000
avatar

Well might as well use pixel margins then.

edit:

Quote:

And another thought, doesn't offsetHeight/Width give you that automatically? I assume you're trying to do something like: widgetB.y = widgetA.Height + widgetA.y (where I've obviously made up the property names).

Something like that. Though more like:
widgetA.height = document.body.clientHeight - padding - whatever;

edit2, I should note, its closer to this:

widgetA.height = document.body.clientHeight - padding - whatever;
widgetB.height = widgetA.offsetHeight - whatever;

doesn't quite work.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Go to: