胖鸭 2009-01-14 09:35 采纳率: 66.7%
浏览 425

检索 HTML 元素的位置(x,y)

I want to know how to get the X and Y position of HTML elements such as img and div in JavaScript.

转载于:https://stackoverflow.com/questions/442404/retrieve-the-position-x-y-of-an-html-element

  • 写回答

24条回答 默认 最新

  • 三生石@ 2009-01-14 09:43
    关注

    HTML elements on most browsers will have:-

    offsetLeft
    offsetTop
    

    These specifiy the position of the element relative its nearest parent that has layout. This parent can often be accessed bif the offsetParent property.

    IE and FF3 have

    clientLeft
    clientTop
    

    These properties are less common, they specify an elements position with its parents client area (padded area is part of the client area but border and margin is not).

    评论

报告相同问题?