我可以用鼠标的绝对位置:获取鼠标的相对位置下降DIV
$(document).mousemove(function(e) {
window.x = e.pageX;
window.y = e.pageY;
});
我怎样才能得到相对于特定的div这个位置?
我可以用鼠标的绝对位置:获取鼠标的相对位置下降DIV
$(document).mousemove(function(e) {
window.x = e.pageX;
window.y = e.pageY;
});
我怎样才能得到相对于特定的div这个位置?
您可以使用div的偏移:
$(document).mousemove(function(e) {
var offset = $(yourdiv).offset();
window.x = e.pageX - offset.left;
window.y = e.pageY - offset.top;
});
这有窍门。谢谢。 – 2013-03-25 14:36:04
刚刚从DIV
你的问题的内容和标题的offsetLeft和的offsetTop减去clientX和ClientY似乎不同。如果你绑定到文档,什么是“父母”? – 2013-03-25 14:23:31
检查鼠标移动的jquery文档:http://api.jquery.com/mousemove/ – a0viedo 2013-03-25 14:27:20
@dystroy:标题不好,你是对的。在mousedown上,我需要与下降的div相关的coordenates。 – 2013-03-25 14:29:26