源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

JS控制图片等比例缩放的示例代码

  • 时间:2020-12-31 22:04 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:JS控制图片等比例缩放的示例代码
[u]复制代码[/u] 代码如下:
<SCRIPT language="JavaScript"> function DrawImage(ImgD,FitWidth,FitHeight){       var image=new Image();       image.src=ImgD.src;       if(image.width>0 && image.height>0){           if(image.width/image.height>= FitWidth/FitHeight){               if(image.width>FitWidth){                   ImgD.width=FitWidth;                   ImgD.height=(image.height*FitWidth)/image.width;               }               else{                   ImgD.width=image.width;                   ImgD.height=image.height;               }           }           else{               if(image.height>FitHeight){                   ImgD.height=FitHeight;                   ImgD.width=(image.width*FitHeight)/image.height;               }               else{                   ImgD.width=image.width;                   ImgD.height=image.height;               }           }       }   }   </script>
调用方法:
[u]复制代码[/u] 代码如下:
<a href="admin/<? echo $rscase['path']?>" target="_blank"><img src="admin/<? echo $rscase['path']?>" alt="点击放大图片" width="180" height="180" onload='javascript:DrawImage(this,180,);' hspace="3" vspace="3" border="0" /></a>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部