1
今天我试图操纵图像时遇到了IE8的一个有趣的情况。IE8 jQ设置CSS属性(宽度或边距)被忽略
我正在更换加载的图像通过更改它们的URL和它们何时加载我试图正确地挤压它们并以视口元素为中心(新图像不像前辈那样是正方形)。 但在IE8(没有测试IE7,并从同事那里听到IE9 - 是所有罚款)图像不按比例,他们只是下降的原始大小和我
img.height(105);
img.css('margin-left', (shift?-shift:0));
被简单地忽略。 这里是代码与问题剪断。
$('.people-images img').each(function() {
var img = $(this);
var oUrl = img.attr('src');
oUrl = oUrl.replace(/[SM]Thumb/, 'LThumb');
img.bind('load', function() {
var img = $(this);
if (this.width > this.height) {
var shift = (this.width/(this.height/105) - 105)/2;
img.height(105);
img.css('margin-left', (shift?-shift:0));
}
else {
var shift = (this.height/(this.width/105) - 105)/2;
img.width(105);
img.css('margin-top', (shift?-shift:0));
}
});
img.attr('src', oUrl);
img.attr('style', null);
img.parent().attr('style', null);
});
请查看我的自我解答。