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

源码网商城

js同比例缩放图片的小例子

  • 时间:2020-08-07 00:33 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:js同比例缩放图片的小例子
[u]复制代码[/u] 代码如下:
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;             }         }     } }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部