简体   繁体   中英

Page loading div loads endless sometimes

My pre page load script sometimes bugs out and is “loading” endless.

No console logs. Page is loaded correctly under the cover div.

It's hard to explain any logic to moment it happens, looks like random thing.

custom.js:

$(function() {
    $(window).on("load", function(){
        $('#loader').css("display", "none", function() {
          $(this).remove();
        });
        $('html, body').css({
            'overflow': 'auto',
        })
    })
});

header.php:

<body <?php body_class('d-flex flex-column h-100 no-scroll');?>>

<div id="loader"><p>Loading</p></div>
    <?php wp_body_open(); ?>

    <header class="site-header”>

[...]

I'm using Wordpress.

You can remove the onLoad listener from your function. That might be a problem due to variaous reasons. Can you try:

$(window).on("load", function(){
    $('#loader').css("display", "none", function() {
      $(this).remove();
    });
    $('html, body').css({
        'overflow': 'auto',
    })
})

On load

$( window ).on("load", function() {
    ...trigger load
});

When document loaded

$( document ).ready(function() {
   ...remove loading
});

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