我有一个宽度为800,高度为600的盒子。
然后我的屏幕尺寸(容器)为1000,高度为700。
然后,如果我们说:
x = container
y = rectangle
z = point in space
引擎仅根据x
中的坐标输出z,因此我需要计算z
中y
的坐标。
我有:
z
size of x
size of y
coordinate of z in x
我想要什么?
z
y
的坐标
答案 0 :(得分:4)
$("#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>
答案 1 :(得分:1)
它仅为相关容器提供坐标
这是脚本
$(document).ready(function(){
$("#container").click(function(e){
alert(e.pageX - $("#container").parent().offset().left);
alert( e.pageY - $("#container").parent().offset().top);
});
});