I need help..
I have put together a script for a context menu. It works or should i say worked great until i added the script to a page with some other relative and absolute positioned layers..
here is the first part of the code i have used
//set the variables
var i5 = (document.getElementById&&document.all); // Check browsers
var n6 = (document.getElementById&&!document.all);
var x,y,ele,maxW,maxH,eBuf=10;
//Add event listeners
if (n6) document.addEventListener("mouseup",showMenu,false);
if (i5) document.attachEvent("oncontextmenu",showMenu);
if (i5) document.attachEvent("onclick",showMenu);
function showMenu(evnt) {
//Set the Screen Max sizes to maxW and maxH
if (i5) {maxW=document.body.offsetWidth, maxH = document.body.offsetHeight;}
if (n6) {maxW=innerWidth; maxH=innerHeight;}
if (document.getElementById) {
//Get Mouse Position
x= (i5)?event.x n6)?clientX=evnt.clientX:false;
y= (i5)?event.y n6)?clientY=evnt.clientY:false;
ele = document.getElementById("menu");
.......... The rest of the script merely sets the layer to x and y and then makes it visible...
The problem i have is that if i trigger the menu over the page, it works fine, but if i trigger it over another layer that is say positioned: relative, the x and y co-ordinates are taken from the mouse position inside that layer. The menu is then moved to that position on the main document.
Im not sure if that makes sense, but basically need to get the position of the mouse in relation to the actual document body and not any layers that the mouse may happen to be over at the time.
Any ideas or am i going about this the wrong way.. ??
Edit: Grrrr slimies
[This message has been edited by andy_j (edited 08-27-2002).]