jQuery get the location of an element relative to window

后端 未结 7 1515
小鲜肉
小鲜肉 2020-11-28 01:20

Given an HTML DOM ID, how to get an element\'s position relative to the window in JavaScript/JQuery? This is not the same as relative to the document nor offset parent sinc

相关标签:
7条回答
  • 2020-11-28 02:08

    This sounds more like you want a tooltip for the link selected. There are many jQuery tooltips, try out jQuery qTip. It has a lot of options and is easy to change the styles.

    Otherwise if you want to do this yourself you can use the jQuery .position(). More info about .position() is on http://api.jquery.com/position/

    $("#element").position(); will return the current position of an element relative to the offset parent.

    There is also the jQuery .offset(); which will return the position relative to the document.

    0 讨论(0)
提交回复
热议问题