浏览器 获取图片width 和height 的方法
1.如果是页面img 元素 直接读取其 naturalWidth
2.如果只有一个url ,可以通过创建一个Image 对象,load 后,异步读取器width 属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div class="container">
<img width="100" src="https://www.baidu.com/img/bd_logo1.png" id="abc"/>
</div>
<script>
var src ="https://www.baidu.com/img/bd_logo1.png";
var image = new Image()
image.src = src;
image.onload = function() {
alert(image.width)
}
alert( document.getElementById("abc").naturalWidth);
</script>
</body>
</html>