您的位置:下载首页 » 技术文章
图片超出预定大小等比例缩小 图片按比列缩小
2010/9/7 15:49:08 | 来源:众智源码网 | 浏览:次阅读

此方法是通过JS实现图片等比例缩小,效果是当图片超出预定大小就自动等比例缩小。此方法宽度和高度超出都会按比例缩小。前段时间有个方法是利用expression来实现控制图片最大宽度。

JS代码
<script language="JavaScript">
<!--
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 200/200){
if(image.width>200){
ImgD.width=200;
ImgD.height=(image.height*200)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}

}
else{
if(image.height>200){
ImgD.height=200;
ImgD.width=(image.width*200)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}

}
}
}
//-->
</script>

html代码
<img src="1.jpg" onload="javascript:DrawImage(this);" />




 上一篇文章:鼠标经过出现大图提示       下一篇文章:控制图片最大宽度
   (合作)  [email protected]
© CopyRight 2009-2010, PK63.NET, Inc.All Rights Reserved.
网站备案号: 版权声明 
如何获得资源分  下载帮助  联系我们