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

前端 未结 29 3099
忘了有多久
忘了有多久 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:05

    Before using real image size you should load source image. If you use JQuery framework you can get real image size in simple way.

    $("ImageID").load(function(){
      console.log($(this).width() + "x" + $(this).height())
    })
    

提交回复
热议问题