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

前端 未结 8 2149
时光说笑
时光说笑 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:08

    It looks to me like the accepted solution modifies the appearance of the object. Occasionally jQuery is a little too helpful and you have to tell it to get out of your way. If you want to use naturalWidth or naturalHeight then just use the one that already exists by converting the jQuery object into a native browser element reference.

    var Height = document.getElementById($(this).attr("id")).naturalHeight;
    

提交回复
热议问题