js动态加载图片,读图片大小

发布时间:2017年1月16日 作者:sieye 查看次数:1266


<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb_2312-80">

<title>js动态加载图片,读图片大小</title>


</head>


<body>


<div id="showImg" style="width:100px;height:100px;background-color:#CCC022;">

</div>


<script language=javascript> 

<!--

var tSetSize;

var tImg = new Image();

tImg.src = "http://www.sieye.cn/upPicDv/201091422331850.jpg";

tImg.onload = function() {

alert(this.width + ':' + this.height);

if(this.width>this.height)

{

tSetSize=" width=100%";

}

else

{

tSetSize=" height=100%";

}

document.getElementById("showImg").innerHTML="<img src='http://www.sieye.cn/upPicDv/201091422331850.jpg' " + tSetSize +" />";

}

//--> 

</script>

</html>



版权所有!www.sieye.cn
E.Mail:sieye@sohu.com QQ:66697110