Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Mouse position in mm not px

Posted on 2013-10-29
3
226 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 43

Assisted Solution

by:Rob
Rob 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 43

Assisted Solution

by:Rob
Rob 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
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 invoke it on a web page. 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.: (CODE)

840 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