getting mouse position relative to content area of an element

前端 未结 4 1025
臣服心动
臣服心动 2020-12-15 09:25

When the mouse is moved over an element, I want to get the mouse coordinates of the cursor relative to the top-left of the element\'s content area (this is the area excludin

4条回答
  •  长情又很酷
    2020-12-15 09:54

    In your element_position(e) function, iterate through the hierarchy using parentNode, get the padding, offsets and border using getComputedStyle(e, null).getPropertyValue(each_css), and sum them to the value of your x and y values before return.

    There's a post proposing a cross-browser reading of styles here:

    http://bytes.com/topic/javascript/answers/796275-get-div-padding

提交回复
热议问题