How to get image size (height & width) using JavaScript?

前端 未结 29 3148
忘了有多久
忘了有多久 2020-11-21 05:23

Are there any JavaScript or jQuery APIs or methods to get the dimensions of an image on the page?

29条回答
  •  春和景丽
    2020-11-21 06:09

    var img = document.getElementById("img_id");
    alert( img.height + " ;; " + img .width + " ;; " + img .naturalHeight + " ;; " + img .clientHeight + " ;; " + img.offsetHeight + " ;; " + img.scrollHeight + " ;; " + img.clientWidth + " ;; " + img.offsetWidth + " ;; " + img.scrollWidth )
    //But all invalid in Baidu browser  360 browser ...
    

提交回复
热议问题