Solved

Mouse position in mm not px

Posted on 2013-10-29
3
225 Views
Last Modified: 2013-11-13
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
Comment
Question by:tonelm54
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 167 total points
ID: 39609402
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
 
LVL 42

Assisted Solution

by:Rob Jurd, EE MVE
Rob Jurd, EE MVE earned 333 total points
ID: 39615980
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
 
LVL 42

Assisted Solution

by:Rob Jurd, EE MVE
Rob Jurd, EE MVE earned 333 total points
ID: 39615982
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Where do I learn ES6? 3 69
Angular - code works but need to make a change 14 32
Converting dates in JavaScript 2 35
jquery datatables, asp.net MVC 9 41
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question