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

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

    Also (in addition to Rex and Ian's answers) there is:

    imageElement.naturalHeight
    

    and

    imageElement.naturalWidth
    

    These provide the height and width of the image file itself (rather than just the image element).

提交回复
热议问题