我在这里有一个很奇怪的问题 - 我正在使用 jquery 来调整我的背景图像的大小(png,宽度:1793,高度:1200,大小:872kb)。
我的功能在这里:
bgInit = function(img, clbk) {
var bgObj = $('#bgImg');
var bgHeight = bgWidth = 0;
bgObj.attr('src',img).ready(function(){
var bgRatio = bgObj.height()/bgObj.width();
if (bgHeight < screen.height) {
bgHeight = screen.height;
bgWidth = bgHeight/bgRatio;
}
if (bgWidth < screen.width) {
bgWidth = screen.width;
bgHeight = bgWidth*bgRatio;
}
//resize and center horizontally
bgObj.height(bgHeight).width(bgWidth).css('margin-left',(screen.width-bgWidth)/-2);
clbk();
});
}
这就是我所说的:
bgInit('img/bg.png', function(){
alert('done!');
});
函数在所有浏览器中都可以正常工作,但问题是在调整大小后使用淡入淡出效果。这真的很慢 - Opera 没有问题,但我想说的是 IE 中的 2fps。
有没有更好的方法来进行这种调整大小(保持纵横比至关重要)?
提前致谢,
米克