...

View Full Version : Tool to determine (X,Y) coordinates



xibitech
07-27-2006, 10:37 AM
Hi,

Is there any tool that can determine the (x,Y) position of a certain pixel on my screen?

Many thanks,
Xibi

Kor
07-27-2006, 10:48 AM
maybe of a certain object, not of a certain pixel. Pixels are measurement units, not objects... So? You need to know the absolute coordinates of an object (the left-top corner)?

xibitech
07-27-2006, 10:53 AM
Thanks for your help.

I meant a tool that can provide me with the ability to point on a certain pixel in my screen with my mouse, and it will tell me exact (X,Y) coordinate of that pixel.
Otherwise for me (as a not experienced javascripter) positioning is trial and error.

Hope it's clear,
Xibi

Kor
07-27-2006, 10:59 AM
Aha, you want to know in fact the position of the mouse measured in pixels. Here's a variant which will show the coordinates of the mouse onclick:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/JavaScript">
var posx;var posy;
function getMouse(e){
posx=0;posy=0;
var ev=(!e)?window.event:e;//IE:Moz
if (ev.pageX){//Moz
posx=ev.pageX+window.pageXOffset;
posy=ev.pageY+window.pageYOffset;
}
else if(ev.clientX){//IE
posx=ev.clientX+document.body.scrollLeft;
posy=ev.clientY+document.body.scrollTop;
}
else{return false}//old browsers
document.onclick=function(){
document.getElementById('mydiv').firstChild.data='X='+posx+' Y='+posy;
}
}
</script>
</head>
<body onmousemove="getMouse(event)">
<div id="mydiv">&nbsp;</div>
</body>
</html>

xibitech
07-27-2006, 11:03 AM
Thanks.

RexxCrow
07-28-2006, 09:41 PM
I have a question on this, could this be taken a step further an used in conjunction with creating a floating menu that follows along from its top or middle both for horizontally and vertically aligned menus? That would be pretty neato!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum