动态调整图像大小并保持纵横比 [英] Resize image on the fly and keep aspect ratio

查看:177
本文介绍了动态调整图像大小并保持纵横比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要调整图片大小以在不同尺寸的不同页面上显示,保持原始图像的宽高比。

I need to resize an image to display on different pages in different sizes, keeping the aspect ratio of the original image.

我可以以编程方式执行此操作吗?需要预加载不同大小的图像

Can I do it programatically or do I need to preload images of different sizes

推荐答案

如果只设置图像的宽度或高度,请保留其他尺寸未指定,浏览器将按比例缩放图像,同时保持其宽高比。

If you set just the width or just the height of an image and leave the other dimension unspecified, the browser will scale the image proportionally while maintaining its aspect ratio.

工作演示: http://jsfiddle.net/jfriend00/NRLQ5/

这篇关于动态调整图像大小并保持纵横比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆