开发者

Getting the Starting left position and top position of an element

In javascript I have a problem with a script I am writing. I need to be able to get the starting top and left positions of an html object like a table or an image that are defined in the CSS.

When I define the left(20px) and top(20px) offsets for the table I run the javascript console built into chrome and do parseInt(document.getElementById开发者_开发知识库('component1').style.left) to see if it will give me the magnitude of the offset as a number. However, it returns NaN. I'm guessing because the browser isn't initializing these values(I thought setting it explicitly in the CSS, that the browser would)

Any ideas as to how I can get around this?


Is jQuery an option? If so:

var offset = $("#component1").offset;
//use offset.left, offset.top for whatever you need

If not, you can do this by looping, see this answer.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜