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

Menu Position


Poster: mmitchell
Dated: Friday January 2 2009 - 22:15:08 GMT

I am using the drag drop feature to allow users to reposition the Menu.

After the menu is dropped the function _DDstop() fires. In that function I try and use _X and _Y to get the X and Y offsets so I can set a cookie and remember the value for the next page load however the _X and _Y values are "close" to what they should be but are not exact.

Currently I am using the following code to get it to work

Code:
function surveyMenuSavePosition(x,y) {
    // set a cookie here using x and y. Not shown in this example but you get the ide
}
function _DDstop()
{
   _gm=$c("menu"+DragLayer);
   _gm.style.zIndex=_zi;
   if(!resetFollowScrollers&&_m[DragLayer][19])_m[DragLayer][19]=Y_-_sT-(gp[2]/2)
   inDragMode=0;
   var p = $('menu0').positionedOffset();
   surveyMenuSavePosition(p[0],p[1]);
}


but the following code SHOULD work

Code:
function surveyMenuSavePosition(x,y) {
    // set a cookie here using x and y. Not shown in this example but you get the ide
}
function _DDstop()
{
   _gm=$c("menu"+DragLayer);
   _gm.style.zIndex=_zi;
   if(!resetFollowScrollers&&_m[DragLayer][19])_m[DragLayer][19]=Y_-_sT-(gp[2]/2)
   inDragMode=0;
   surveyMenuSavePosition(X_,Y_);
}


Please that in the working example I am using Prototype.js to do
Code:
var p = $('menu0').positionedOffset();

This works fine BUT using $('menu0') is not the best way to refer to a menu since that could change in the future.


Anyone know how to use X_ and Y_ or if there is a better way to get the menu left and top offset in an absolutely positioned menu?

Re: Menu Position


Poster: Andy
Dated: Monday January 5 2009 - 17:17:35 GMT

Hi,

Does your menu have a name? if so you could reference it by name like this:

Code:
var myMenu = gmobj("menu"+getMenuByName("Menu Name"))


Then you could use the gpos() function to return the top and left values for the menu like this:

Code:
var menuPos = gpos(myMenu);


gpos returns an array of values for the specified object in pixels as follows: [top,left,height,width]

Code:
var menuTop=menuPos[0];
var menuLeft=menuLeft[1];

Maybe you could use that instead.

Also, I think X_ and Y_ change based on mouse position so it will always be wrong if the mouse moves even slightly.

HTH,
Andy

Re: Menu Position


Poster: mmitchell
Dated: Tuesday January 27 2009 - 16:17:03 GMT

I can confirm that my code now works great

Correct Milonic code + my custom object "SS"

Code:
   var myMenu = gmobj("menu"+getMenuByName("questionMenu"))
   var menuPos = gpos(myMenu);
   SS.surveyMenuSavePosition(menuPos[1],menuPos[0]);




Previously Incorrect code using Prototype.js + positionedOffset() + my custom object "SS"
This was incorrect because assuming "menu0" was a bad thing
Code:
   var p = $('menu0').positionedOffset();
   SS.surveyMenuSavePosition(p[0],p[1]);



Thanks again Andy!