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

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

    You can apply the onload handler property when the page loads in js or jquery like this:-

    $(document).ready(function(){
       var width = img.clientWidth;
       var height = img.clientHeight;
    
     });
    

提交回复
热议问题