史上最牛X最简洁的Javascript图片缩放代码

源码:

function resize(img, width, height) {
 (img.width > img.height)
 ? ((img.height = Math.min(height, width * img.height/img.width)) || (img.width = Math.min(width, img.width)))
 : ((img.width = Math.min(width, height * img.width/img.height)) || (img.height = Math.min(height, img.height)));
}

 

稍微压缩一下:

function resize1(i,w,h){var a=i.width;var b=i.height;a>b?((i.height=Math.min(h,w*b/a))||(i.width=Math.min(w,a))):((i.width=Math.min(w,h*a/b))||(i.height = Math.min(h,b)));}

posted @ 2009-12-22 13:33  笑的自然  阅读(147)  评论(0)    收藏  举报