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

时间:2014-02-10 19:20:05

标签: javascript css

以下是我的图片:http://cameronlimbrick.com/work/visual-art/paintings/item/thoughts

我想保持现有的最大高度,但是,当窗口不够高以适应整个图像时,我希望它自动缩小以适应高度。谢谢你的帮助。

2 个答案:

答案 0 :(得分:1)

你可以尝试

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
}

答案 1 :(得分:1)

它应该有效!

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