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

Load Menu based on reference element ID


Poster: luegner
Dated: Saturday June 4 2005 - 1:05:02 BST

I was just curious if it's possible to load the menu using absolute positioning based on the coordinates of a reference element id like a div tag? You would then specify the offset from that reference element so the menu could be loaded at those coordinates.

1. Get top and left position of reference element based on its ID.
2. The menu would define a top and left offset from that element.


Poster: Ruth
Dated: Sunday June 5 2005 - 15:40:12 BST

Hi,

I'm not sure about the reference element id. I know there are pop function menus which can be positioned by image id/names. Sample 23 and Sample 24

There was also a function written in the forum to 'openAsMainAtImage' The only reason I remember is because it was done for me to get a main menu positioned at the right side of the page without having to actually put the menu in a table.

I can't find the post, don't know if it got lost on one of the forum crashes or what, but the example is still here. Basically it turns any standard submenu into a main menu, so to use it you'd set up the main as a sub, i.e. not put in the top, left, screenposition, alwaysvisible etc. The example is set with a top=25; and followscroll="0,40,5"; That was just for testing to see if they worked with the function, in case someone used it just to get the menu to set at the right hand side of the page.

I don't know if this will do what you want. Like the others it does requries an image, but maybe you could put in a little 1x1px transparent image in the div? One thing to note on this function: Once the menu opens, it's there to stay. Since you're not really opening it inside of the table cell, if the page is narrowed, the menu won't move, even if the table cell moves (taking the image with it). If you want to have the menu reposition itself when that happens, then you'll have to implement an onresize handler.

And, if you ask me what any of that is, like an onresize handler, I have no clue :? [though I can figure out what it must do :lol: ] Kevin was so kind as to write this for me, but since I ended up not using the layout, I never got around to asking about the onresize handler which I"d think is necessary. He's out this week and I think he'd have to be the one to do that.

Ruth


Poster: luegner
Dated: Monday June 6 2005 - 16:26:42 BST

Sample 24 is probably the closest to what I'm talking about but it only functions for submenus which limits you for menu options. I'm a bit surprised that with all the menu options there are that this one a little overlooked. The need for this is pretty great for such things as cached google websites. What happens is google inserts a header at the top of a cached website effectively shoving the website down vertically several pixels and as a result the menu stays in the same spot because it's based on fixed positioning. The idea here would be that if code was inserted into a page or even the font was enlarged for example, the menu could flow with the design by referencing it to an element instead of just setting its absolute position. This is also good if you have a follow scroll menu.


Poster: Ruth
Dated: Monday June 6 2005 - 23:11:32 BST

You can position it in a table and set it to relative position. It would then move with the table. I would think putting it in a table would be the best solution. If the menu is at the top, then you could place a single column/row table there the height of the menu, place the menu in it, according to the relative positioned table bound directions. For such things as you mentioned about google then I would think that would take care of the issue. I know a lot of people use tables to position the menu so that it moves with the flow as the resolution etc., is changed and the layout shifts.

If your intent was to use the element id to place the menu in a div, you are not supposed to place the menu in a div.

Ruth


Poster: kevin3442
Dated: Tuesday June 7 2005 - 1:07:08 BST

Hi luegner,

The popup() function used in sample 24 is not limited to submenus. In fact, the way the menu code is structured, there really are no "main" menus and "sub" menus. There are only menus. Any given menu can be a parent of another menu, or the child of another menu, or both, depending on how you decide to arrange the hierarchy.

If you're interested in coding the position of the menu so that it can be set programatically at run time, then you'll find the popup() function useful, as well as other functions described on the built-in methods page.

For example, gmobj() returns an object reference not just to a menu, but to any other object on the page that has an id/name. If you have a div, then pass the div's id to gmobj() to get the object reference to it. You could then use the object to get teh div's position; in fact, I thing you could even use gpos() to do that, even though it was meant for use with menus (I think it'll work for any object, once you have the object reference). Then use gmobj() to get a reference to the menu you want to open. Pass that to spos(), along with the coordinates you got from the div (and any offsets you want to apply), to set the position of the menu. Then call popup() to open the menu.

Alternatively, you could try setting the id and name of the div, then pass that to popup() as the second parameter, along with top and left offsets in the third and fourth parameters. This is normally done to open a menu from the location of an image, but you should be able to popup() a menu from the location of other id'd objects.

Some places to start anyway...

Cheers,

Kevin


Poster: luegner
Dated: Thursday June 16 2005 - 22:01:07 BST

The popup function didn't sound like something I needed but I did find your function:

Code:
function mm_changeMenuProperty(menuName, propertyRef, newValue)
{
  var menuNum = getMenuByName(menuName);
  _m[menuNum][propertyRef] = newValue;
BDMenu(menuNum);
}


It's a great function and mm_changeMenuProperty('Main Menu', 2, 20); works but mm_changeMenuProperty('Main Menu', 3, 10); doesn't? I tested it with other properties like menuWidth and it changes it but it doesn't do it for left for some reason. I checked the value of the left property before it's changed and it gets the right value. I checked it after it changes the value and it changes but the menu simply doesn't move to the new left position; it just keeps the default left position originally declared in the menu definition. Have you experienced this?


Poster: luegner
Dated: Friday June 17 2005 - 0:26:26 BST

It seems your function breaks the menu causing it not to load at all on version 5.726. It was working on 5.718. For some reason Andy decided to remove if(_W.buildOffScreen) from the from the g$ function. buildOffScreen I believe is a global variable to remove flicker or something. Anyway it's gone in 5.726 so that when you call to BDMenu breaks the menu. Strangely enough, if you either reinsert if(_W.buildOffScreen) or take out BDMenu in your function, it works again (the way it did before, changing the left property still doesn't work).


Poster: kevin3442
Dated: Wednesday June 22 2005 - 0:33:06 BST

Hi Again,

Sorry for the delayed reply... been out and about, traveling.

Yes... v5.726 appeared to have some issues with some of the custom functions that have appeared in this forum over time. I'm not 100% sure, but I believe they work fine again with v5.727. Will test.

I have found that there are some menu properties that are too complex to change effectively with mm_changeMenuProperty(). Menu position is one of them. As you've seen, the property value does indeed change, but the change does not necessarily take effect.

When changing the menu position programatically (i.e., moving it around), it's best to get the menu object reference using gmobj() and then use that to set the new position using spos().

If you need help with that approach, holler.

Kevin


Poster: luegner
Dated: Wednesday July 13 2005 - 20:55:18 BST

Your suggestion to use the spos function does not work for menus which utilize followscroll. It seems there aren't any errors relating to the (undocumented?) BDMenu function anymore (5.728) but just to test, I took out the function again and it seems to have no impact on using your function to change the top coordinates of the menu. Unfortunately the function still can't change the left position of the menu permanently but that is less of a problem anyway. It would be nice if spos actually worked with always available menus but until that time comes, I can use your function.


Poster: Andy
Dated: Friday July 15 2005 - 14:24:10 BST

spos should work with alwaysvisible menus providing they are not positioned relative or contained inside another object, like a table or a div.

If you download a copy of the menu and add this to the HTML:

Code:
<script>
   function click()
   {
      menuObj=gmobj("menu"+getMenuByName("main menu"))
      spos(menuObj,200,200)
   }
</script>

<a href=javascript:click()>Click</a>


Then click on "Click" you'll see the menu move.


Hope this helps
Andy


Poster: luegner
Dated: Wednesday July 27 2005 - 19:52:35 BST

I know the spos function works for alwaysvisible menus. It just doesn't work for alwaysvisible __and__ followscroll menus. When followscroll is set, the menu disgregards spos and prefers the default top and left coordinates which are set within the "root" alwaysvisible followscroll menu. The menu is absolute positioned and is not contained within a div, object or table. So far the mm_changeMenuProperty is the only function which can accomplish this task when adjusting the top position of an alwaysvisible followscroll menu.


Poster: Ruth
Dated: Wednesday July 27 2005 - 21:57:39 BST

Hi,

I don't know if this might help at all, but it's a pretty indepth explanation of followscroll and its different uses, something about it being set to act as a boolean or not. :? It's about 1/3 down in the 2nd post.

http://www.milonic.com/forum/viewtopic. ... 6027#16027

Ruth


Poster: luegner
Dated: Wednesday July 27 2005 - 22:29:44 BST

Thanks for the info but this deals with menu positioning more than followscroll. The problem is that the spos function cannot override the menu position when followscroll is set. It has nothing to do with whether or not I implemented followscroll properly.


Poster: Ruth
Dated: Thursday July 28 2005 - 2:55:21 BST

Hi leugner,

I am so sorry. I didn't mean to imply that you had improperly set followscroll.

I don't understand a lot of that information and wasn't sure if there was something in there that would allow you to use the followscroll with the spos.


Ruth