0

I built a simple css preloader that should fade out with jQuery once the page has been completely loaded with all images etc.:

$(document).ready(function() {
    // Preloader
    $(window).on('load', function() {
        $('#loader').delay(350).fadeOut('slow');
        $('#preloader-bg').delay(1000).fadeOut('slow');
    });
}); 

The problem is that the window load event is not reliably triggered inside the document ready function. Once the page has been cached it seems to work, but it is not triggered the first time the site is loaded.

Is there a workaround?

eisbehr
  • 12,243
  • 7
  • 38
  • 63
  • 1
    _Why_ are you trying to wrap a load event handler into the ready handler in the first place? – CBroe Aug 10 '16 at 12:17
  • Then take a look at the `plugin` example of this answer. You can simply build something by yourself. But there is no further discussion needed: `load` in a `ready state` is a **no-go** since jQuery 3.x. – eisbehr Aug 10 '16 at 12:19
  • I've extended the answer in the duplicate with an example how you can do it. – eisbehr Aug 10 '16 at 12:36

0 Answers0