目的:用js获取图片真实的宽高
适用场景:在有图片的页面中,需要点击图片查看原图如下图,这时就需要获取图片的原始宽高。
js获取图片原始宽高:
$(".comment-img img").each(function() { var image = new image(); var src=$(this).attr("src"); var realwidth=0; var realheight=0; image.onload = function () { realwidth = image.width; realheight=image.height; } });
如对本文有疑问, 点击进行留言回复!!
offset、client、scroll (width,height、left,top、X,Y)
网友评论