`
jbeduhai
  • 浏览: 504288 次
  • 性别: Icon_minigender_1
  • 来自: 山东
社区版块
存档分类
最新评论

图片缩放 小记

阅读更多
<html>
<head>
<title>test image</title>
<script language="javascript" src="js/drawImage.js"></script>
</head>

<body>

<img src="img/mm.jpg" border="0" onload="javascript:drawImage(this, 60, 80);" />
<img src="img/mm.jpg" border="0" onload="javascript:drawImage(this, 120, 120);" />
<img src="img/mm.jpg" border="0" onload="javascript:drawImage(this, 200, 150);" />

<img src="img/23.jpg" border="0" onload="javascript:drawImage(this, 60, 80);" />
<img src="img/23.jpg" border="0" onload="javascript:drawImage(this, 120, 120);" />
<img src="img/23.jpg" border="0" onload="javascript:drawImage(this, 200, 150);" />

<p>&nbsp;</p>

<img src="img/woyo.jpg" border="5" />
<img src="img/woyo.jpg" border="0" onload="javascript:drawImage(this, 320, 8000);" />
<img src="img/woyo.jpg" border="0" onload="javascript:drawImage(this, 5000, 300);" />

</body>
</html>


drawImage.js

function drawImage(ImgD, x, y) {
	var ratio = ImgD.width / ImgD.height;
	ImgD.width = ((ratio >= x/y) ? x : ratio * y);
	ImgD.height = ((ratio >= x/y) ? x/ratio : y);
}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics