与Chrome浏览器的jQuery位置问题 [英] jQuery position problem with Chrome
问题描述
当我提醒值 .position()。left
时,它会在 Chrome 。与其他浏览器一起返回实际的数字。为什么会发生这种情况?
基于Webkit的浏览器(例如Chrome和Safari)可以访问图像 width
和 height
属性。其他浏览器只要加载DOM就可以访问这些信息(它们不需要完全加载图像来知道它们的大小)。
所以,如果你在您的页面中有图片,使用基于Webkit的浏览器,您应该在 $(window).load
事件之后访问 offset
而不是在 $(document).ready
事件之后。
When I alert the value .position().left
, it returns 0 on Chrome. With other browsers it returns the actual number. Why does this happen?
Webkit based browsers (like Chrome and Safari) can access images width
and height
properties only after images have been fully loaded. Other browsers can access this information as soon as just the DOM is loaded (they don't need to load the images entirely to know their size).
So, if you have images in your page, with Webkit based browsers you should access offset
information after the $(window).load
event fires, and not after the $(document).ready
event.
这篇关于与Chrome浏览器的jQuery位置问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!