Get full size of image in javascript/jquery

后端 未结 4 1751
甜味超标
甜味超标 2021-02-15 02:53

I have an image on page that has been resized to fit in a div, say, 400x300. How can I get the full size of the image (~4000x3000) in jQuery? .width() and .height() only seem to

4条回答
  •  抹茶落季
    2021-02-15 03:10

    You can do this with an Image object that holds the same source file like:

    var preloader = new Image();
    preloader.src = 'path/to/my/file.jpg';
    
    preloader.onload = function(){
    var height = preloader.height;
    var width = preloader.width;
    }
    

提交回复
热议问题