【问题标题】:Getting absolute 'top' position from a mouse event (Javascript/jQuery)从鼠标事件中获取绝对“顶部”位置(Javascript/jQuery)
【发布时间】:2009-06-25 18:10:01
【问题描述】:

在 mouseenter/mouseleave 事件中,我想捕获表格单元格的绝对“顶部”位置。

到目前为止,事件是这样附加的:

$('td[someAttr]').mouseenter(function(mouse) {
   // how do we get the td's top absolute position?

   //FYI: mouse.pageX and mouse.pageY would give the mouse position
});

【问题讨论】:

    标签: javascript jquery mouseevent


    【解决方案1】:
    $(this).offset().top
    

    【讨论】:

    • 这不会给出绝对的顶部;它将给出相对于其父元素的位置;见docs.jquery.com/CSS/position
    • 是的,我在您的评论和回答之前更改为抵消
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-13
    • 1970-01-01
    • 1970-01-01
    • 2011-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多