Solved

Mouse position in mm not px

Posted on 2013-10-29
3
216 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 42

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

by Julian Matz As of jQuery (http://jquery.com/) 1.4 the .live() method (http://api.jquery.com/live/) supports custom events as well as some standard JavaScript events that it previously didn't support. Among these is the submit event. Unlike …
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now