做最好的自己~~

Be My Personal Best!

导航

转:图片等比例缩放,图片指定宽或高按比例缩放,图片不变形缩放

<!--
//slt.js开始
//图片等比例缩小
function DrawImage(ImgD,kw,kh)
{
var image=new Image();
image.src=ImgD.src;
if(image.height<image.width)//说明宽》高==》以宽为标准
{
   if(image.width>kw)
   {
    ImgD.width=kw;
    ImgD.height=(image.height*kw)/image.width;
   }
}
else//以高为标准
{
   if(image.height>kh)
   {
    ImgD.height=kh;
    ImgD.width=(image.width*kh)/image.height;
   }
}
}
// -->

调用例子:
<script language="javascript" src="slt.js"></script>
<img src="1_68.jpg" border="0" onload='javascript:DrawImage(this,50,69);'>

posted on 2008-07-23 23:36  阿万  阅读(830)  评论(0编辑  收藏  举报