简体   繁体   中英

Fade preloader on page load

I have a gif which I want to set as a website preloader. But when I do so the preloader doesn't dissappear even after page load. I have tried various java scripts but none of them proved to be of use.

 $(window).on("load", function() { $(".loading").fadeOut("slow"); });
 .loading { background: #f4ded3 url('https://i.pinimg.com/originals/db/e6/b9/dbe6b90d0fd0d209001cb64eefd038d7.gif') no-repeat center center; position: absolute; top: 0; left: 0; height: 100%; width: 100%; background-size: contain; z-index: 9999999; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="loading"></div> <div class="content">Test</div>

Alternatively you can do this

 $(document).ready(function() { $(".loading").fadeOut("slow"); });
 .loading { background: #f4ded3 url('https://i.pinimg.com/originals/db/e6/b9/dbe6b90d0fd0d209001cb64eefd038d7.gif') no-repeat center center; position: absolute; top: 0; left: 0; height: 100%; width: 100%; background-size: contain; z-index: 9999999; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="loading"></div> <div class="content">Test</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM