[英]Re-sizing an image with Javascript if image is bigger than the viewport
目前,我正在处理此代码以使用javascript调整图像大小
function resize(which) {
var elem = document.getElementById(which);
if (elem == undefined || elem == null) return false;
if (max == undefined) {
if (elem.width > document.documentElement.clientWidth) {
} else if (elem.height > document.documentElement.clientHeight) {
} else if (elem.height > document.documentElement.clientHeight && elem.height > document.documentElement.clientWidth) {
}
}
if (elem.width > elem.height) {
if (elem.width > max)
elem.width = max;
} else {
if (elem.height > max)
elem.height = max;
}
}
我想知道我是否朝着正确的方向使用javascript调整图像的大小,如果图像较大则客户端视口。 我也希望对此有所帮助,因为我不知道下一步该怎么做才能完成代码。 谢谢。 :)
之前有人问过类似的问题:
调整图像大小以适合屏幕
另外,这个jQuery插件似乎完全可以满足您的需求:
http://code.google.com/p/jquery-imagefit-plugin/
如果在高度为100%,宽度为100%的元素上执行:
http://www.tutwow.com/htmlcss/quick-tip-css-100-height/
这是此解决方案的示例:
http://jsfiddle.net/nottrobin/zndkg/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.