当前位置:首页 >> 网页设计 >> java >> 图片按比例缩放函数 >> 内容

图片按比例缩放函数

作者:趣趣虎 来源:www.ququhu.com 时间:2007-09-05
<script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
    //参数(图片,允许的宽度,允许的高度)
    var image=new Image();
    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="images/toplogo.gif" onload="javascript:DrawImage(this,100,100)">
文章关键字:函数 比例 图片 image.width image.height ImgD.height
165 * 70 广告位招租
联系QQ:349881211
165 * 60 广告位招租
联系QQ:349881211
网友发表评论:
昵称:趣趣虎网友 (您未登陆,默认匿名评论)
评论内容:不能超过250字,请自觉遵守互联网相关政策法规,请勿发布AD或不相关的内容!
验证码
热点文章
相关文章
相关连接
相关连接
图片连接