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

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

    it is important to remove the browser interpreted setting from the parent div. So if you want the real image width and height you can just use

    $('.right-sidebar').find('img').each(function(){
        $(this).removeAttr("width");
        $(this).removeAttr("height");
        $(this).imageResize();
    });
    

    This is one TYPO3 Project example from me where I need the real properties of the image to scale it with the right relation.

提交回复
热议问题