views:

82

answers:

1

Hi,

I have quite an odd problem here - I am using jquery for resizing my background image (png, width: 1793, height: 1200, size: 872kb).

My function is here:

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();
    });
}

And this is how I'm calling it:

bgInit('img/bg.png', function(){
alert('done!');
});

Function works fine in all browsers, but the problem is when it comes to using fade effects after resizing. It's really laggy - Opera has no problems, but 2fps in IE I'd say.

Is there any better way for doing this kind of resizing (maintaining aspect ratio is crucial)?

Thanks in advance,

Mikk

+1  A: 

Internet explorer JavaScript engine is separate from the browser core and runs very slowly compared to other modern browsers. Since Javascript is the only way to dynamically resize, you are out of luck with IE. My own site suffers from the same issue. And my script is not based on jQuery, it is highly optimized.

What you can do is use a google plugin to speed up IE javascript engine around 10X times, you can include a simple script in your site that will help customers to install it if they want to - http://code.google.com/chrome/chromeframe/

Check out web dev resources here - http://www.chromium.org/developers/how-tos/chrome-frame-getting-started

See some recent performance test results to know what I am talking about: http://www.legitreviews.com/article/1347/1/

avok00
I don't think that this is really correct. Yes, the rendering engine and Javascript are separate, as is the case in **all** browsers. However, when the Javascript code resets style attributes to alter the size of an element, it's not the Javascript engine that performs the resulting layout adjustment - it's the rendering engine.
Pointy
You may take a look at this picture http://ieblog.members.winisp.net/images/Dean_PPB4_5.png part of this article - http://blogs.msdn.com/b/ie/archive/2010/08/04/html5-modernized-fourth-ie9-platform-preview-available-for-developers.aspx to see what I mean. Besides, you don't know if the slow down is when the style attributes are altered of when the layout is adjusted. Finally it does not matter, because the solution I pointed out replaces the rendering engine too.
avok00