can't get true height/width of object in chrome

后端 未结 4 1345
囚心锁ツ
囚心锁ツ 2021-02-06 03:20

I have a question, if i set a image height in css and try to get height/width i get different results in different browsers. Is there a way to get the same dimension in all brow

4条回答
  •  失恋的感觉
    2021-02-06 03:46

    The images aren't loaded in document.ready, you need to use the window.load event to make sure they're present, like this:

    $(window).load(function(){
        $("#text").append($("#img_0").height());
        $("#text").append($("#img_0").width());
    });
    

    Here's a quick read on the difference, the important part is that pictures are loaded.

提交回复
热议问题