前端开发

 首页 > 前端开发 > jquery教程 > js图片等比例缩放

js图片等比例缩放

分享到:
【字体:
导读:
          //图片比例缩放控制 www.zixuephp.com functionDrawImage(ImgD,FitWidth,FitHeight){varimage=newImage();image.src=ImgD.src;if(image.width0image.height0){if(image.width/image.height=FitWidth/FitHeight){if(image.widthFitWidth){ImgD.width=F...

//图片比例缩放控制 www.zixuephp.com

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; 
            } 
        }   
    } 
}

 

实例如下:


" onload="javascript:DrawImage(this,500,500);">


分享到:
jQuery封装一个动态加载js和css插件
今天给大家带来jQuery封装一个动态加载js和css插件 //动态加载js,css  //www.zixuephp.com  $.extend({      include: function(file)      {          var files = typeof file == "string" ? [file] : file;                    for (var i = 0; i 
生成二维码的 jQuery 插件:jquery.qrcod...
jquery.qrcode.js 是一个纯浏览器 生成 QRcode 的 jQuery 插件,它使用非常简单,生成的 QRcode 无需下载图片,并且不依赖第三方服务,比如最近 Google 服务在国内访问不稳就造成我好几个网站的 QRcode 不能使用,并且压缩之后大小小于 4K。 jquery.qrcode.js 使用 1. 加载 jQuery 和 jquery.qrcode.js: 2. 创建一个...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……