开发者

Chrome's changing height when loading pictures - how to get actual height with jQuery on load

I have the following:

var offset = {top: target.offset().top + target.height() + 3,
                  left: target.offset().left};
target.offset(offset);

this happens on $(document).ready(..)

However, in chrome, the target object is not positioned with the appro开发者_Python百科priate height. When I placed an alert(..) to show the actual height, I saw the reason - target.offset().top returns less than desired because at that moment an image still isn't loaded (the alert blocks the loading of the page and this becomes visible).

I fixed the issue by specifying an explicit height of the <div> around the image, but is there a better way?


Instead of $(document).ready(..), use $(window).load(...) for this :)

The window onload event doesn't happen until after images are finished loading, so that's what you want in these cases.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜