简体   繁体   English

将图像高度缩放到浏览器窗口

[英]Scale image height to browser window

Here is my image: http://cameronlimbrick.com/work/visual-art/paintings/item/thoughts 这是我的形象: http//cameronlimbrick.com/work/visual-art/paintings/item/thoughts

I would like to keep the existing maximum height, however, when the window is not tall enough to fit the entire image, I would like it to automatically shrink to fit the height. 我想保持现有的最大高度,但是,当窗口不够高以适应整个图像时,我希望它自动缩小以适应高度。 Thanks for your help. 谢谢你的帮助。

You could try 你可以试试

img.your-image-class {
    height: 100%; //automatically retains aspect ratio
    max-height: 755px; //don't let it get bigger than this (755px is its current height I checked your link
}

It's should work! 它应该工作!

$(document).ready(){
   var h = $(window).height();
   if (h < 755)
   {
       $('.img.your-image-class').css("max-height",h + "px")
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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