waynegm / imgViewer

jQuery plugin to zoom and pan images, even those with a size that is a percentage of their container
MIT License
55 stars 13 forks source link

pos.x real width. Not 1 #6

Closed wap4444 closed 9 years ago

wap4444 commented 9 years ago

How can I change coordinates on this $("#click_position").html(e.pageX + " " + e.pageY + " " + pos.x + " " + pos.y); to pos.x real width of image?

waynegm commented 9 years ago

The cursorToImg function returns relative image coordinates. Just multiply the x coordinate by the image width and the y coordinate by the image height to get the corresponding image pixel.

var relpos = self.cursorToImg( e.pageX, e.pageY );
var imgposX = pos.x * $("#image").prop('naturalWidth');
var imgposY = pos.y * $("#image").prop('naturalHeight');
wap4444 commented 9 years ago

waynegm, thank you! But i have result like that "Click Position x757.8571428571423 y481.5848214285711" How can I get result like thaht "Click Position x757 y481"

waynegm commented 9 years ago

Use the javascript Math.round method

var imgposX = Math.round(pos.x * $("#image").prop('naturalWidth'));
var imgposY = Math.round(pos.y * $("#image").prop('naturalHeight'));
waynegm commented 9 years ago

As I haven't heard back I presume your now OK so I'll close this.