<script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD){
var image=new Image();
var iwidth = 80; //定义允许图片宽度
var iheight = 80; //定义允许图片高度
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//-->
</script>
<img src=".." onload = "DrawImage(this)">
图象按比例 缩放
原创文章如转载,请注明:转载自悠悠博客 [ http://www.ajaxstu.com/ ]
相关文章:
- 自定义提示条(2007-11-9 9:26:27)
- javascript if else语句摘要(2007-11-6 1:7:7)
- JavaScript实用技巧集锦(2007-10-27 1:12:14)
- javascript加密与解密(2007-10-18 10:4:26)
- SHA-1加密算法在javascript中的实现(2007-10-15 7:50:37)
- JScript错误代码及相应解释大全(2007-10-10 4:26:47)
- DOM属性速查表(2007-10-1 7:7:33)
- JavaScript:gb2312转unicode(2007-9-26 8:0:59)
- js初学者容易犯的几个错误(2007-9-20 2:57:14)
- JS的IE和Firefox兼容性汇编(2007-9-13 2:27:16)
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
