javascript - Get mouse position relative to a zoomed out div -


what i'm looking accomplish position of mouse in relation zoomed out div matrix transform. see in fiddle below have red div width of 4000px, since it's zoomed out appears smaller said 4000px. should happen if click on intersecting lines in red div, relx should read (around) 2000 , rely should read around 325.

$(".crazywide").click(function(e){     var clickpos = $(this).offset();      var relx = e.pagex - clickpos.left;     var rely = e.pagey - clickpos.top;      //used display current click coords     $(".debug").empty();     $(".debug").prepend("relx: " + relx + " rely: " + rely); }); 

fiddle

the element shrunk factor of 0.12 in both directions. such, can calculate relative mouse click position dividing relx , rely 0.12:

$(".debug").prepend("relx: " + (relx / 0.12) + " rely: " + (rely / 0.12)); 

updated fiddle


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -