Problem with jQuery fadeOut!

0

I'm trying to make a PRELOADER that will appear before loading the page. The problem is that even after the page is loaded it does not disappear. I have the following code

HTML:

<div id="preloader"></div>

CSS:

#preloader{
  position: fixed;
  left: 0;
  top: 0;
  z-index: 999;
  width: 100%;
  height: 100%;
  background: $white url("../img/loading.gif") no-repeat center center;
  background-size: 80px;
}

jQuery:

$(window).load(function() {
  $("#preloader").delay(500).fadeOut("slow").remove();
});
    
asked by anonymous 26.07.2017 / 00:06

2 answers

1

You can use the document.onreadystatechange event. When it is triggered just check the status, if it is complete , hide #preloader , follow example:

document.onreadystatechange = function () {
   if (document.readyState == "loading") {
      //Mantem o #preloader visivel
   }else if(document.readyState == "complete") {
      $("#preloader").fadeOut("slow");
   }
}
    
26.07.2017 / 01:55
1

You're calling the wrong callback in the wrong window event, try this fiddle here (I made some simple modifications not to use URL): link

$(document).ready(function() {
  $("#preloader").delay(500)
  .fadeOut("slow", function() { 
    return $("#preloader").remove() 
  })
});
    
26.07.2017 / 00:34