Closed Thread Icon

Topic awaiting preservation: mouse position problem (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8283" title="Pages that link to Topic awaiting preservation: mouse position problem (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: mouse position problem <span class="small">(Page 1 of 1)</span>\

 
andy_j
Nervous Wreck (II) Inmate

From: uk
Insane since: Aug 2002

posted posted 08-27-2002 13:51

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).]

andy_j
Nervous Wreck (II) Inmate

From: uk
Insane since: Aug 2002

posted posted 08-27-2002 14:38

Well i have managed to fix the problem by setting x and y using

if (i5) { x=event.clientX; y=event.clientY; }
if (n6) {x=evnt.clientX; y=evnt.clientY; }

where evnt is the event passed to the function..

I think that is the right way around it, but would be glad of any pointers..

Give me regex's any day

Thanks

« BackwardsOnwards »

Show Forum Drop Down Menu