Menu Position

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
mmitchell
Beginner
Beginner
Posts: 2
Joined: Fri Jan 02, 2009 11:08 pm
Location: Hatboro PA

Menu Position

Post by mmitchell »

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: Select all

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: Select all

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: Select all

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?
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Re: Menu Position

Post by Andy »

Hi,

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

Code: Select all

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: Select all

var menuPos = gpos(myMenu);
gpos returns an array of values for the specified object in pixels as follows: [top,left,height,width]

Code: Select all

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
mmitchell
Beginner
Beginner
Posts: 2
Joined: Fri Jan 02, 2009 11:08 pm
Location: Hatboro PA

Re: Menu Position

Post by mmitchell »

I can confirm that my code now works great

Correct Milonic code + my custom object "SS"

Code: Select all

	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: Select all

	var p = $('menu0').positionedOffset();
	SS.surveyMenuSavePosition(p[0],p[1]);

Thanks again Andy!
Post Reply