代码之家  ›  专栏  ›  技术社区  ›  Bozho

Chrome在加载图片时改变高度-如何使用jQuery在加载时获得实际高度

  •  0
  • Bozho  · 技术社区  · 14 年前

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

    这发生在 $(document).ready(..)

    alert(..) 为了显示实际高度,我看到了原因- target.offset().top 返回的值小于所需值,因为此时仍没有加载图像(警报会阻止页面加载,这将变为可见)。

    height <div> 但是有更好的方法吗?

    1 回复  |  直到 14 年前
        1
  •  2
  •   Nick Craver    14 年前

    $(document).ready(..) $(window).load(...) 为此:)

    onload 事件直到 之后