//图片等比例压缩
var scaleImage = function (w, h, o) { var img = new Image(); //img.height=$("#imgBig").height(); //img.width=$("#imgBig").width(); img.src = o.src; if (img.width > 0 && img.height > 0) { if (img.width / img.height >= w / h) { if (img.width > w) { o.width = w; o.height = (img.height * w) / img.width; } else { o.width = img.width; o.height = img.height; } o.alt = img.width + "x" + img.height; } else { if (img.height > h) { o.height = h; o.width = (img.width * h) / img.height; } else { o.width = img.width; o.height = img.height; } o.alt = img.width + "x" + img.height; } } }
//图片加载完成以后再进行缩放
document.getElementById("imgBig").onload = function () {
//调用图片压缩
scaleImage(734, 450, document.getElementById("imgBig")); }