[英]is there any javascript library to resize images according to browser window size?
is there any javascript library for resizing the images according to browser window sizes ? 是否有用于根据浏览器窗口大小调整图像大小的JavaScript库?
I need to consider all cases (vertical / horizonal image, vertical / horizonal browser window) 我需要考虑所有情况(垂直/水平图像,垂直/水平浏览器窗口)
NB The image scale has to be the same! 注意图像比例必须相同! (no distorsions) (无失真)
thanks 谢谢
不知道这是否正是您的意思,但是我在我的一个项目中使用了“ Supersized” jquery插件(它提供了diashow功能,但是如果只传递一个图像,可能就是您想要的): http:// www.buildinternet.com/project/supersized/还有一个“ bgStretcher”插件,看起来差不多,但是我还没有使用它: http ://www.ajaxblender.com/bgstretcher-jquery-stretch-background -plugin.html
I came up with this solution. 我想出了这个解决方案。 Is this insane in your opinion ? 您认为这是疯了吗? It works.. :) 有用.. :)
var scale = 1;
if ( imageWidth > imageHeight) {
if ( imageWidth > windowW) {
scale = windowW / imageWidth;
if ( (imageHeight * scale) > windowH) {
scale = scale * (windowH / imageHeight);
}
} else {
if ( imageHeight > windowH) {
scale = windowH / imageHeight;
if ( (imageWidth * scale) > windowW) {
scale = scale * (windowW / imageWidth);
}
}
}
} else {
if ( imageHeight > windowH) {
scale = windowH / imageHeight;
if ( (imageWidth * scale) > windowW) {
scale = scale * (windowW / imageWidth);
}
} else {
if ( imageWidth > windowW) {
scale = windowW / imageWidth;
if ( (imageHeight * scale) > windowH) {
scale = scale * (windowH / imageHeight);
}
}
}
}
imageHeight = imageHeight * scale;
imageWidth = imageWidth * scale;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.