我想加載html,然後得到真實的圖像高度。如何使用JQuery獲得真正的圖像高度?
$("#cover").html(stuff); //this has the image inside it
$(function(){
console.log($("#cover img").height()); //sometimes it's 0
});
出於某種原因,高度爲0,有時難道是因爲圖像沒有被完全加載的是,和JQuery視其爲0?如果是這樣,我該如何克服這一點?圖像加載時是否有回調或什麼?
您的圖像是否有'none'的顯示? –