pos.x real width. Not 1
Closed this issue · 4 comments
wap4444 commented
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
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
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
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
As I haven't heard back I presume your now OK so I'll close this.