Bar*_*din 1 javascript css jquery image
我处于这种情况; 当其中一个在css上定义为0时,需要计算图像的原始值width和heigth值.我无法用jQuery更改CSS,需要像这样解决:
CSS:
img { width:0px; }?
Run Code Online (Sandbox Code Playgroud)
jQuery的:
var imgHeight = $('img').height();
alert(imgHeight);//which returning 0 ofcourse
Run Code Online (Sandbox Code Playgroud)
我希望用更少的代码实现这一点,谢谢,
试试这个:
var img = $("img")[0];
alert( img.naturalWidth + "x" + img.naturalHeight );
Run Code Online (Sandbox Code Playgroud)