首页 > js 如何知道一个网络图片的高宽

js 如何知道一个网络图片的高宽

js 如何知道一个网络图片的高宽
var img = new Image(); img.src = obj.src; console.log('width:'+img.width+',height:'+img.height) img.onload = function(){ console.log('width:'+img.width+',height:'+img.height) };
已经找到方法了,虽然那个啥,鄙人不喜欢用jq 一切原生重写


var img = new Image();
img.onload = function(){
    alert(img.width);
    alert(img.height);
}
img.src = 'http://s..com/img/logo@2x.png';

图片加载完成事件中可以获得图片原始高宽

$('img').load(function(){
    this.width   //图片实际宽度
    this.height// 实际高度
});
【热门文章】
【热门文章】