SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    positioning layers relatively to window size

    Hi

    I want my divs (position: absolute) to be positioned relatively to window size

    My page is a main table with one cell containing all the rest

    This cell (anf thus my page) is centered (top and left)

    Each menu link has onMouseOver which shows (visibility) the corresponding layer (div)

    Each visible/invisible layer is positioned on the same spot

    I use absolute positioning for the divs because some browsers don't support positioning relative to tables

    My question: is the following code the only solution or am I making my life (slightly) complicated over nothing?

    This thing works on NN4, 6 7, IE 4, 5, PC and Mac -- that I know of; repositions divs onResize, with reLoad fix for !#+x! NN4

    I get the window size:

    Code:
    function define_window()
    {
    	if(document.layers||document.getElementById)
    		{
    		win_W = window.innerWidth;
    		win_H = window.innerHeight;
    		}
    
    	if(document.all)
    		{
    		win_W = document.body.clientWidth;
    		win_H = document.body.clientHeight;
    		}
    }
    Then I put the divs where I want them:

    Code:
    function position_layers()
    {
    winWidth = win_W;
    winHeight = win_H;
    
    var max_left = 220;
    var max_top = 140;
    
    horiz = Math.round((winWidth - 180) / 2);
    	if(horiz < max_left)
    	{
    	horiz = max_left;
    	}
    
    verti = Math.round(((winHeight - 220) / 2));
    	if(verti < max_top)
    	{
    	verti = max_top;
    	}
    
    for(i=0;i<9;i++)
    	{
    	my_layer = 'div'+i
    	budge(my_layer,horiz,verti)
    	}
    }
    The 'budge()' function calls some code which positions the div (top and left of div object) on the page after getting the browser type

    So, your input is welcome.

    Regards everyone
    Last edited by pietro; Jun 19, 2003 at 09:18.

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi pietro, nice work.

    Is it online?


  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well thanks )

    It's online, yes -- just one dead unfinished homepage I did for a job I was hoping to do, but didn't (client had one of his employees -- whose job is to do a bit of print layout -- do it for a cheaper price and the promise of fancy Flash pages)

    Anyway, I'm sending you the url by private message (I'd rather keep it confidential as name of client appears on the page)

    Cheers
    Last edited by pietro; Jun 20, 2003 at 00:05.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •