pulling the X coordinate for each item in a horizontal menu

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
twesson
Advanced
Advanced
Posts: 14
Joined: Sun Feb 15, 2004 7:10 pm
Location: Chicago, IL

Post by twesson »

Bit by bit we got it!

Thanks for your help.

Here is the code -- some minor alterations regarding the frame. I removed some specific-use code I had in there.

//distantMenu - opens up milonic menuName inside of mainmenu_body
function distantMenu( menuName )
{
parent.frames['mainmenu_body'].popdown();
strItemPos = gpos(gmobj("el"+_itemRef));
parent.frames['mainmenu_body'].spos(parent.frames['mainmenu_body'].gmobj("menu" + parent.frames['mainmenu_body'].getMenuByName(menuName)),null,strItemPos[1],null,null);
parent.frames['mainmenu_body'].popup(menuName);
}
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hmmm... yep, I forgot that the menu objeject had to be gotten from the content frame; glad to see you got it.

It occurs to me that it would probably be more efficient to change the distantMenu() function in the nav frame so that all it does is get the x coordinate and pass it and the menuName to a function in the content frame that would set the position and open the menu. In other words, like this:

In menu_data.js in the nav frame:

Code: Select all

function distantMenu(menuName)
{
  strItemPos = gpos(gmobj("el"+_itemRef));
  parent.frames['mainmenu_body'].openSubmenu(menuName, strItemPos[1]);
}
In menu_data.js in the content frame:

Code: Select all

function openSubmenu(menuName, left)
{
  popdown();
  spos(gmobj("menu" + getMenuByName(menuName)),null,left,null,null);
  popup(menuName);
}
This would require fewer references of the content frame from the nav frame (1 instead of 5). Anyway, just a thought...

Have you tried this in various browsers? I was wondering if you might end up having to do a little sniffing and apply a browser-specific offset to the x coordinate?

Kevin
twesson
Advanced
Advanced
Posts: 14
Joined: Sun Feb 15, 2004 7:10 pm
Location: Chicago, IL

Post by twesson »

This was for an IE-only internet browser app so I didn't investigate beyond that. I do however have a confident feeling for cross-browser functionality because an actual X-coordinate was available. My guess is like yours -- that an offset to the X-coord would be the only variable to deal with.
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

I've been following this and trying to figure out how to use it to set the submenus so that they will center with regard to the item from which they drop. I think that what you are doing here would allow me to do that, but it's kind of given in pieces on how to do each thing and I can't figure out how you would put it together to 1st find the location of the menu item, then tell the submenu that opens from it to center from that menu item's references as to location and width. Is it possible using what is here, and how would i put them together into one function.

Ruth
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hi Ruth,

Will you be trying to do this across frames or all on one page? (I'll probably be able to take a crack at it tomorrow.)

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

Post by Ruth »

Not frames. I've always wanted to be able to position the middle submenus so they are centered from their parent item. I'm pretty sure that wouldn't be a good idea for the first and last item of the main menu because I use screen position center and you never know the visitor's browser window size, so centering those items might have part of them hidden off the screen.

Ruth
priceofacoke910
Beginner
Beginner
Posts: 1
Joined: Wed Jan 04, 2006 7:52 pm
Location: Chilhowie, VA
Contact:

Post by priceofacoke910 »

Andy wrote:Here are some internals that might be of use.

getMenuByName("menuname")
Will return the reference number for a menu.

gmobj("objname")
Will return a reference to an object, for example:

Code: Select all

myMenu = gmobj("menu"+getMenuByName("mainmenu"))
Will set myMenu variable as the mainmenus object. You can then use this to get and set properties.

To get the dimensions of a menu, use:

Code: Select all

myMenu = gmobj("menu"+getMenuByName("mainmenu"))
menuDimensions=gpos(myMenu)
This creates an array with the menu dimensions and positioning, like this:

menuDimensions[0] // Top
menuDimensions[1] // Left
menuDimensions[2] // Height
menuDimensions[3] // Width


To set the position of a menu, use spos(), like this:

Code: Select all

myMenu = gmobj("menu"+getMenuByName("mainmenu"))
spos(myMenu,10,10,200,200)
syntax: spos(myMenu,top,left,height,width)

The above aren't just for menus, they can be used for any HTML object.

Hope this helps
Andy
Hi, I made a pop-up menu in Dreamweaver and need to reposition the child-menus and I am unsure if this code can apply to the javascript associated with that menu or if there is a more specific way to do it in that menu. You can look at just the menu at: http://newchillsdesign.chillsnet.org/test/menu.html

This menu is incorperated already in the main site, but I really need the "Public Services" child menus repositioned. I have read so many tutorials asked many people over the past couple weeks and cannot figure it out. I can read the "javascript" make-up of the menu and understand the basic make up, but I don't understand commands or things like that. Thanks for any help you can give.
Mike C. Nichols
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Hi Mike,

Unfortunately, you've found the wrong site. The Milonic website and these forums are for the Milonic DHTML Menu. I had a quick look at your code, and you're using an entirely different menu system: mm_menu, from MacroMedia. From looking at the js code, it seems that system may have last been updated in 2002, and dates back to 1997. Milonic Menus can do what you want. If you'd care to try them out, you'll find plenty of on-line and downloadable samples from the main site, http://milonic.com

Good luck,

Kevin
Post Reply