Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:06

How do I position the MainMenu using a javascript function ?


Poster: krogstrup
Dated: Saturday October 23 2004 - 22:46:32 BST

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:
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:
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 :-)


Poster: Maz
Dated: Saturday October 23 2004 - 23:09:05 BST

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


Poster: krogstrup
Dated: Saturday October 23 2004 - 23:12:24 BST

Hi maz

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

How would that work ?


Poster: Maz
Dated: Saturday October 23 2004 - 23:50:44 BST

The references you need are probably here:
http://www.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


Poster: Ruth
Dated: Sunday October 24 2004 - 2:21:54 BST

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


Poster: krogstrup
Dated: Sunday October 24 2004 - 6:55:27 BST

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 ? :-)


Poster: krogstrup
Dated: Sunday October 24 2004 - 7:31:17 BST

I´ve looked at these two pages:

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

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

I´ve tryed this:

Code:
drawMenus();
spos(gmobj("Main Menu"),null,121,null,null);


to force the left position of Main Menu to be 121, but nothing happens....


Poster: krogstrup
Dated: Sunday October 24 2004 - 8:07:30 BST

YEAH - finally :-)

Here is the solution:

Code:
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:
<body onResize="setLeftPosOfMainMenu(findMenuLeftStart());">


This works just GREAT !!!!!

Thanks for your answers, comments and inputs !!!!


Poster: krogstrup
Dated: Sunday October 24 2004 - 8:39:45 BST

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:
_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 ?


Poster: krogstrup
Dated: Sunday October 24 2004 - 8:46:33 BST

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 ?


Poster: krogstrup
Dated: Sunday October 24 2004 - 8:50:31 BST

aaaaaaah - got it :-)

I need to specify this for my Main Menus subs:

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