Prevent user to perform any actions while page is loading

前端 未结 4 1689
小鲜肉
小鲜肉 2020-12-20 18:09

I have a tabbed web application, and I also created caching of the images before page transitions, so when the user goes to a page, I make sure all the images are downloaded

相关标签:
4条回答
  • 2020-12-20 18:20

    You can use a predefined jQuery UI called jQuery Block UI

    Or simply add a division that will block the body and will fade out when the body is loaded.

    <div id="div">
        <h1>Please Wait..</h1>
    </div>
    

    jQuery will be:

    $(document).ready(function(){
        $("#div").fadeOut()
      });
    

    Here is the working Example. The page will be blocked until the image is loaded completely.

    0 讨论(0)
  • 2020-12-20 18:21

    I use:

    $(window).bind('load', function() {
        // code here
    });
    

    Until the page is not completely loaded this event is not fired. So, there, you can call a function that unlock your page's elements.

    Enjoy :)

    0 讨论(0)
  • 2020-12-20 18:27

    Covering the interface with a top-level transparent/translucent overlay should block events for elements beneath it.

    However, you would be taking UI control away from the user by doing this.

    0 讨论(0)
  • 2020-12-20 18:34

    This JQuery code can disable elements on page:

    $("body").find("*").attr("disabled", "disabled");
    $("body").find("a").click(function (e) { e.preventDefault(); });
    

    And this JQuery code will make elements enabled again:

    $("body").find("*").removeAttr("disabled");
    $("body").find("a").unbind("click");
    
    0 讨论(0)
提交回复
热议问题