简体   繁体   English

如何使IE 8中的背景图像按比例扩大?

[英]How to make background image expand proportionally in IE 8?

I have a div with a background image, within a wrapping as such: 我有一个带有背景图像的div,在这样的包装内:

<div id="imageholder">
  <div id="image">
  </div>
</div>

#imageholder {
width: 100%;
height: 500px;
overflow: hidden;
}

#image {
width: 100%;
height: 100%;
background-image: url(image.jpg);
background-size: cover;
/*IE HACK*/
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='image.jpg', sizingMethod='scale'); 
}

The filter IE method works somewhat - it stretches the image length wise but not proportionally height wise, like background-size:cover does. 过滤器IE方法有些起作用-像background-size:cover一样,它在长度方向上拉伸图像,但在高度方向上不按比例拉伸。

Does anyone know a way to stretch the background image proportionally in IE (so the vertical overflow is hidden by #imageholder)? 有谁知道一种在IE中按比例拉伸背景图像的方法(因此#imageholder隐藏了垂直溢出)?

Possibly, no method to scale the image in proportion except increase size of the image holder. 可能没有办法按比例缩放图像,除非增加图像支架的尺寸。 Here you can set height of imageHolder to percent proportionate to the image referred in the filter. 在这里,您可以将imageHolder的高度设置为与过滤器中引用的图像成比例的百分比。

尝试将图像支架的高度设为自动或百分比。

I made a way to do this in JQuery. 我在JQuery中做到了这一点。 Its not the proper way and I dont like it but it may help someone: 这不是正确的方法,我不喜欢它,但它可能会帮助某人:

$(window).resize(function() {

var windowwidth = $(window).width();

var windowsize = windowwidth - 500;

var windowsize = windowsize + "px";

if(windowwidth > 1100){

      $('#image').css({ height: windowsize });

};

});

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

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