开发者

How to get postion of html tag on screen? [duplicate]

This question already has answers here: Closed 12 years ago.

Possib开发者_C百科le Duplicate:

Screen Coordinates of a element, via Javascript

So what I need is simple - find out where on users screen (NOT browser window) top left corner of element is?


On the user's screen? You can't do that. I'm sure you could code something up like that with a Java applet or similar, but not with JavaScript.

The closest you can get is by getting the position of the browser window using the window.screenX and window.screenY properties on IE, and the window.screenLeft, etc properties on other browsers, then getting the relative offset of the element using the method described here (from Breezer's answer), and adding the coordinates together. Unfortunately, this doesn't account for toolbars or sidebars in the browser, so this is a really rough estimate. Don't do this if you need it to be 100% accurate.


if you use jquery you can use http://api.jquery.com/position/ other wise you have to use offset read more about it here http://www.quirksmode.org/js/findpos.html


It seems that this is possible after all; see this w3schools item (IE) and this other w3schools (Chrome and FF). I haven't tested this myself, however.

On browsers except Chrome and FF, use window.screenLeft and window.screenTop. On Chrome and FF use window.screenX and window.screenY (I have tested this in Chrome; it works there).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜