• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

Mouse position in mm not px

I'm trying to find out the position of the mouse over an image, which I can easily do by taking advantage of mousemove and then then event.clientX and event.clientY however these values seem to be px and not mm.

It is not to use mm in my actual design,  but Im creating a pdf and want to know position many elements on a pdf so I need to know the measurments in mm, not px.

My initial thought was to layout the image as a 1px = 1mm, so if I wanted an A4 image, I would blow display the image as 210px x 297px, however is too small.

My problems with sizing isnt really a problem, as I can solve that at a later date, my issue is detecting the mouse position, so what Ive got soo far is:-
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>mousemove demo</title>
  <style>
  </style>
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>

<img id="imgPDF" src="01.png" height="297px" width="210px" />

<script>
    $("#imgPDF").mousemove(function( event ) {
      var clientCoords = "( " + event.clientX + ", " + event.clientY + " )";
      document.title = clientCoords;
    });
</script>

</body>
</html>

Open in new window


Any ideas?

Thank you
0
tonelm54
Asked:
tonelm54
  • 2
3 Solutions
 
Chris StanyonCommented:
I think you'll struggle with this as there is no correlation between mm and px. If a 900px wide image is printed at a resolution of 300dpi then you image is likely to be 3 inches wide (about 75mm). If the same image is printed at 200dpi then your image will be output at 4.5 inches (112mm)
0
 
RobOwner (Aidellio)Commented:
Adding to what Chris has said, mm means nothing in the digital world so there is no formula on converting px to mm because you can transpose px to whatever mm you like and output to any media (screen or print).

Really would love to say there is an answer to this but unfortunately there just isn't a way unless you fix the variables.

The variables are you physical viewable screen size in mm and your screen resolution in px.  If you know these then you can get a reasonably approximate of px to mm.

make sense?
0
 
RobOwner (Aidellio)Commented:
You'll be able to detect the user's screen resolution but they would have to input the viewable physical dimensions of their screen before this would work.  As far as i know you can't detect it.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now