Is there any way to read out the “naturalWidth” of an image with jquery?

前端 未结 8 2150
时光说笑
时光说笑 2020-12-05 10:59

I tried with something like this:

var Height = $(this).naturalHeight;

But it doesn\'t work. Is there any way to do that

greez

8条回答
  •  长情又很酷
    2020-12-05 11:05

    The best you can do is to hide an image without setting the width and height and use the image source for this image as your original image. Then calculate the dimension of this hidden image.

    Or else you can calculate the physical dimension in server side and pass that to a hidden element in the page and fetch the size from that hidden element value.

提交回复
热议问题