一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

js 图片加载效果

时间:2008-09-28 编辑:简简单单 来源:一聚教程网

程序代码
var proMax;
var proMaxWidth  = 120;
function proDownImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
var rate = (proMaxWidth/image.width < proMaxHeight/image.height)?proMaxWidth/image.width:proMaxHeight/image.height;
//如果 指定高度/图片高度  小于  指定宽度/图片宽度 ,  那么,我们的比例数 取 指定高度/图片高度。
//如果 指定高度/图片高度  大于  指定宽度/图片宽度 ,  那么,我们的比例数 取 指定宽度/图片宽度。
    if(rate <= 1){   
     ImgD.width = image.width*rate;   //图片新的宽度 = 宽度 * 比例数
               ImgD.height =image.height*rate;
    }else{    //  如果比例数大于1,则新的宽度等于以前的宽度。
               ImgD.width = image.width;
               ImgD.height =image.height;
    }
     }
}

热门栏目