Yes, there are ways to find both the screen res. and the window size. You can even find them out across browsers:
Code:
var winW,winH,scrW,scrH; //define variables
//Find window dimensions:
if(document.body.clientWidth){ //IE and OperawinW=document.body.clientWidth;
winH=document.body.clientHeight;
}else if(window.innerWidth){ //NS and MozillawinW=innerWidth;
winH=innerHeight;
}
//Find screen dimensions:
scrW=screen.width;
scrH=screen.height;
So using this, winW and winH find the dimensions of the window and scrW and scrH find the screen size. To use it to centre-align your layer, try this (assuming your layer is called 'centLyr'):
Code:
//---------------Change layer name here\/
var centLyr=document.getElementById("centLyr"); //Gets layer
var centLyrWidth=parseInt(centLyr.style.width); //Gets width of layer
//-------------\/Can use scrW instead
var idealLeft=(winW/2)-(centLyrWidth/2); //Get ideal X co-ordinate
centLyr.style.left=idealLeft+"px"; //Positions layer horizontally
Does this help?
Bookmarks