开发者

what is the necessary css for offset.left

This page => http://api.jquery.com/offset does not adequately explain the necessary css involved. Neither do any of the 5 or so SO questions I read , related to this subject touch on CSS issues, either.

1) what CSS will开发者_运维技巧 cause $(this).offset.left to return 'undefined'?

2) It is also necessary to know what other issues will complicate offset.left (eg. will $("object").hide() cause offset.left to return undefined? etc)

I need to know what CSS will kill offset.left and what CSS will return a proper value.

THNX


$(this).offset().left will always return a value. jQuery is determining this value based upon the box model by which browsers render the elements of the page.

CSS provides a way to control the offset values via a defined language, however once rendered it always has a value.

So the answer to your question (and the reason you have not found the answer you are looking for before) is that jQuery and CSS are both controlling/reading an underlying technology. jQuery is not reading CSS rules.


If you hide the element then it is no longer part of the box model, and offset().left will return a value of 0:

DEMO: http://jsfiddle.net/9xaCe/


The page you referenced says:

jQuery does not support getting the offset coordinates of hidden elements

If the element is hidden then I guess .offset will return undefined. So the answer to your question 2 is yes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜