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

1

I have a view that loads a DataTable.Net , where I need to display a PopUp with the message " Aguarde... " .

PopUp opens when the page loads, but how do I close it? The way I did, PopUp does not close, what's wrong? Is there any other more efficient way to do this?

  

Note: I will then replicate this PopUp to be used in other View 's.

Here is 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>
    
asked by anonymous 17.10.2015 / 14:46

1 answer

2

The correct method would be - .hide(); and not .show('hide'); . PopUp is not working because you're basically telling it to open, and then close with .hide(); .

To close the PopUp after the page is fully loaded, it uses $(window).load(function () , along with a fadeOut() pointing to the desired id . This will cause the #divCarregando element to not disappear suddenly, but will dissolve 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><divid="divCarregando" class="progresso">
    <p>Aguarde...</p>
</div>

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

    
17.10.2015 / 16:00