I have a box with a width of 800 and height of 600.
Then my screen size (container) is 1000 and its height is 700.
then, if we say:
x = container
y = rectangle
z = point in space
The engine only outputs the z based on its coordinate in x, therefore I need to calculate the coordinate of z in y.
I have:
z
size of x
size of y
coordinate of z in x
and what I want?
coordinate of z in y
Click for Demo
$("#id").click(function(e){
var parentOffset = $(this).parent().offset();
//or $(this).offset(); if you really just want the current element's offset
var relX = e.pageX - parentOffset.left;
var relY = e.pageY - parentOffset.top;
});
<div id="id">
//or $(this).offset(); if you really just want the current element's offset
</div>
Demo Link
It gives co-ordinates only for related container
Here is Script
$(document).ready(function(){
$("#container").click(function(e){
alert(e.pageX - $("#container").parent().offset().left);
alert( e.pageY - $("#container").parent().offset().top);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With