How do I position the MainMenu using a javascript function ?

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
krogstrup
Advanced
Advanced
Posts: 20
Joined: Sat Oct 23, 2004 10:36 pm
Location: Denmark

How do I position the MainMenu using a javascript function ?

Post by krogstrup »

My website design is centered in the browser and I would like to dynamically set the LEFT position of the main menu by using a javascript function.

My function looks like this:

Code: Select all

var ie4_check = (document.all && !document.getElementById) ?     true : false;
var ie5_check = (document.all && document.getElementById) ?     true : false;

function findMenuLeftStart(){
    if (ie4_check || ie5_check) {
        width = document.body.clientWidth;
        } 
    else {
        width = window.innerWidth;
    }
    
    width = width/2-380
    return(parseInt(width));
}
I have tryed to implement the output from the above function by writing this:

Code: Select all

left=findMenuLeftStart();
But it doesn´t work ?!?

How can I use my function to change the left position of the main menu ?

I know that I could position the menu relative in order to follow my centered design, but this isn´t an option in this case. I really need to be able to set the left pos dynamically.

Hope someone can help me :-)
User avatar
Maz
Milonic God
Milonic God
Posts: 1717
Joined: Fri Jun 06, 2003 11:39 pm
Location: San Francisco
Contact:

Post by Maz »

Could it be like
left="offset=-10px";

Unless you can locate an old topic in search, Kevin might be able to help but not normally on weekends.

maz
krogstrup
Advanced
Advanced
Posts: 20
Joined: Sat Oct 23, 2004 10:36 pm
Location: Denmark

Post by krogstrup »

Hi maz

I´m not sure I understand what you´re saying....?!?

How would that work ?
User avatar
Maz
Milonic God
Milonic God
Posts: 1717
Joined: Fri Jun 06, 2003 11:39 pm
Location: San Francisco
Contact:

Post by Maz »

The references you need are probably here:
http://milonic.com/menu_methods.php

If you need more help try searching for gpos or whatever reference best suits your needs and you might find its been discussed before.

I remember at least one person dynamically setting submenus a long time ago.

I don't know js so I can't really help you in any detail.

maz
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

I'm not sure why you need a javascript function. The menu has a screenposition parameter. You can use that in combination with top to position the menu in the center of the page screenposition="center";

If you need to offset it to the left or right of center a number of pixels then you can use the parameter Maz gave in conjuction with the others. For example: top=50; left="offset=10"; screenposition="center"; would place the menu 50px from the top, center it and then offset it 10 px toward the right, if you need it to go left then you use negatives, i.e. left="offset=-10px";

Ruth
krogstrup
Advanced
Advanced
Posts: 20
Joined: Sat Oct 23, 2004 10:36 pm
Location: Denmark

Post by krogstrup »

This is my problem:

The browser is 100% in width
My design is 760 pixels in width
My design is centered in the browser

I need the main menu to be positioned left BUT within my design area.

Here are a few examples of how different browser window sizes would affect the start position of my main menu:

browser width = 1.000 pixels
1000/2 = center point
1000/2-(760/2) = the starting point of my design

browser width = 850 pixels
850/2 = center point
850/2-(760/2) = the starting point of my design

In this case I cant use screenposition="center"; because then I dont know how many pixels to move my menu to the left ?!?

I need to be able to dynamically allways start my main menu left positioned where my centered design area starts.

Do I make sence ? :-)
krogstrup
Advanced
Advanced
Posts: 20
Joined: Sat Oct 23, 2004 10:36 pm
Location: Denmark

Post by krogstrup »

I´ve looked at these two pages:

http://milonic.com/menu_methods.php (spos function)
viewtopic. ... spos+gmobj (example of how to use spos function)

But I can´t seem to make it work ?!?

I´ve tryed this:

Code: Select all

drawMenus();
spos(gmobj("Main Menu"),null,121,null,null);
to force the left position of Main Menu to be 121, but nothing happens....
krogstrup
Advanced
Advanced
Posts: 20
Joined: Sat Oct 23, 2004 10:36 pm
Location: Denmark

Post by krogstrup »

YEAH - finally :-)

Here is the solution:

Code: Select all

function setLeftPosOfMainMenu(intLeftPos) {
	spos(gmobj("menu" + getMenuByName("Main Menu")),null,intLeftPos,null,null);
}

setLeftPosOfMainMenu(findMenuLeftStart());
and to make sure the menu follows if the user resizes the window:

Code: Select all

<body onResize="setLeftPosOfMainMenu(findMenuLeftStart());">
This works just GREAT !!!!!

Thanks for your answers, comments and inputs !!!!
krogstrup
Advanced
Advanced
Posts: 20
Joined: Sat Oct 23, 2004 10:36 pm
Location: Denmark

Post by krogstrup »

hmmm - now I have a new problem :-(

When I try to offset the position of my subs it doesn´t work.

I´m trying this:

Code: Select all

_subOffsetTop=20              // Sub menu top offset
_subOffsetLeft=20            // Sub menu left offset
but my subs stil shows positioned offsetTop:0 and offsetLeft:0

What am I doing wrong ?
krogstrup
Advanced
Advanced
Posts: 20
Joined: Sat Oct 23, 2004 10:36 pm
Location: Denmark

Post by krogstrup »

I can see that subOffsetTop and subOffsetLeft is used to offset positions of subs to my subs.

But how do I offset the subs to my Main Menu ?
krogstrup
Advanced
Advanced
Posts: 20
Joined: Sat Oct 23, 2004 10:36 pm
Location: Denmark

Post by krogstrup »

aaaaaaah - got it :-)

I need to specify this for my Main Menus subs:

Code: Select all

top="offset=20";
left="offset=20";[code]
Post Reply