Skip to content Skip to sidebar Skip to footer

$(window).load(function(){}); Problem In Opera

I need to recalculate body's main div height, than wait while all content (images) loads and only than show it to site visitor. To achieve this i used jQuery and CSS //CSS looks li

Solution 1:

You need to understand the difference between $(document).ready() and a normal load event (which is basically what $(window).load() would work with).

The "document ready" event occurs when the entire document is ready for JavaScript interaction - all the HTML and JavaScript is loaded. Most likely, not all images are loaded, whether CSS is loaded and applied is somewhat uncertain (browsers do this a bit differently).

For these reasons, doing something that requires layout/size calculations from $(document).ready() is not a good idea. In this case you'll try to read the size of the document before all the images are loaded - so you get the size as it is before the browser knows what the size will be when it knows the size of all images.

It seems to work just fine in Opera here if I make sure this is done on load event rather than document.ready.

(Another issue is that Opera does not load images inside display:none content - until you actually change display so that the images are required. This improves loading performance but sometimes means the user has to wait for images loading when extra content is shown.)


Solution 2:

Try this actually:

//recalculate height when page is fully loaded
 $(window).load(function(){
  $('body').show();
  recalculateHeight("#center_div");
 });

rather than:

$(document).ready(function(){
 $(window).load(function(){
  $('body').show();
  recalculateHeight("#center_div");
 });
});

Solution 3:

A better solution is to specify the height and width of your images in the html. Then you don't need window.load because they won't change in height.

Also I think the point that Sarfraz was making is that you shouldn't put window.load inside document.ready. They should both be at the same level.


Post a Comment for "$(window).load(function(){}); Problem In Opera"