Show "Wait..." message while the page loads in full - MVC jQuery

Asked

Viewed 12,835 times

1

I have a view who carries a Datatable.Net, where I need to display a popup with the message "Aguarde...".

Popup opens when the page is loaded, but how do I close it? The way I did, Popup doesn’t close, what’s wrong? Is there any other more efficient way to do this?

BS.: Then I will replicate this Popup to be used in other View's.

It follows the code below what I already have:

<style type="text/css">
.progresso {
    display: none;
    position: fixed;
    top: 360px;
    left: 50%;
    margin-top: -50px;
    margin-left: -100px;
    vertical-align: middle;
    text-align: center;
    font-size: 16px;
    font-weight: bold;
    background-color: white;
    border: 1px solid black;
    height: 90px;
    width: 120px;
}
</style>
.
//AQUI O HTML É CARREGADO
.

<div id="divCarregando" class="progresso"> 
    <img src="~/Imagens/midi.gif" />
    <br /> Carregando... 
</div>

@section Scripts {
@Scripts.Render("~/Content/css")
@Scripts.Render("~/bundles/DataTables")

<script type="text/javascript">
$(document).ready(function () {
    $('.dropdown-toggle').dropdown();

    $("#divCarregando").show();
    .
    .
    .
    $("#divCarregando").show('hide');
});
</script>

1 answer

2


The correct method would be - .hide(); and not .show('hide');. Popup isn’t working because you’re basically telling him to open it, and then close with the .hide();.

To close the Popup after the page is fully loaded, use the $(window).load(function (), along with a fadeOut() pointing to the id desired. This will cause the element #divCarregando does not disappear suddenly, but rather by dissolving until it disappears completely when the page is fully loaded.

Here’s an example:

$(document).ready(function () {
    $("#divCarregando").show();
    $(window).load(function () {
        // Quando a página estiver totalmente carregada, remove o id
        $('#divCarregando').fadeOut('slow');
    });
});
.progresso {
    display: none;
    position: fixed;
    left: 50%;
    top: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    text-align: center;
    font-size: 16px;
    font-weight: bold;
    background-color: white;
    border: 1px solid black;
    height: 90px;
    width: 120px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>

<div id="divCarregando" class="progresso">
    <p>Aguarde...</p>
</div>

I also took advantage and made some changes in your CSS code to better centralize this "modal box".

  • 1

    perfect! thank you!

  • Chun the way it is already meets my needs, but let’s say that the page load time can vary, in a certain period of day 1 second and another period 3 seconds, so how to work with this time variation ?

  • You’re right @Adrianocordeiro, I didn’t think of that at the time. I have now edited my answer, now it is the right way, to disappear only when the page is fully loaded.

  • 1

    Ball show! Funf perfectly. the/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.