开发者

CSS relative positioning

开发者 https://www.devze.com 2022-12-17 11:34 出处:网络
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.

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;}
    J开发者_如何学GoSFX.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.


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


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消