Q_Mlilo
Q_Mlilo

Reputation: 1787

CSS relative positioning

I am developing a web page with dynamic dimensions i.e I first read the size of the canvas and adjust my elements widths and heights accordingly.

if(!window.JSFX)
    JSFX=new Object();

if(!JSFX.Browser)
    JSFX.Browser = new Object();

if(navigator.appName.indexOf("Netscape") != -1)
{
    JSFX.Browser.getCanvasWidth = function() {return innerWidth;}
    JSFX.Browser.getCanvasHeight    = function() {return innerHeight;}
}
else    if(document.all)    {
    JSFX.Browser.getCanvasWidth = function() {return document.body.clientWidth;}
    JSFX.Browser.getCanvasHeight    = function() {return document.body.clientHeight;}
}

function f(){
var h = JSFX.Browser.getCanvasHeight();
var w = JSFX.Browser.getCanvasWidth();
var elem1 = document.getElementById("left");
var elem2 = document.getElementById("right");

if(h){
elem1.style.height = (h-115)+"px";
elem2.style.height = (h-95)+"px";
elem2.style.width = (w-305)+"px";
} 
else return false; 
 } 

window.onload = f;

// The HTML

<div id="container">
           <div id="left">
           </div>

           <div id="right">
           </div> 
</div>

My problem is that when I resize the window the divs jump all over the place. I need help with CSS and JavaScript I can use to make the divs resizable when the window is resized.

Thanks.

Upvotes: 1

Views: 191

Answers (2)

Paul D. Waite
Paul D. Waite

Reputation: 98786

I think the window object has a resize event that fires when the user resizes their browser.

So, maybe add this at the end of your JavaScript code:

window.onresize = f;

Upvotes: 0

NimChimpsky
NimChimpsky

Reputation: 47280

"position:absolute" and/or "position:fixed"

Upvotes: 1

Related Questions