简体   繁体   中英

Resizing the image based on screen resoultion

我有一个图像...并且如果图像的高度大于maxHeight或宽度大于maxWidth,我想按比例调整图像大小,使其适合maxWidth X maxHeight。

While this can be done, what happens when the user's screen is much bigger than the native size of the image? Do you stretch it to the point of it degrading into pixels?

What happens with people with smaller screens - do they have to waste time and bandwidth downloading an image that is much larger than they're capable if displaying, then depending on the browser to scale the image down?

In many browsers, especially older ones, scaling images degrades them, whether making them bigger or smaller. It's best to scale them on the server, based on a large image and deliver the "right" sized image to the client. This is much more complicated.

While all of this is possible, one must ask whether this really adds much value to the user experience in the first place and whether all this effort is worth it.

You can set the attributes of the image tag using JavaScript.

The properties you may like to set are height, width.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM