Div with load overlap

Asked

Viewed 878 times

0

Hi, I got this div and I made a code in jquery for when to trigger it through an event, it appears, but I want to style it in a way that the div overlays all the content of my page, with a black background with a certain opacity and a show my content of div, I’m trying to style but unsuccessfully.

inserir a descrição da imagem aqui.

Follows my code:

   <div class="mask-loading">
        <figure>
           <img src="img/ajax-loading.gif" alt="carregando...">
           <figcaption class="loading-text"></figcaption>
        </figure>
    </div>
  • I don’t get it. The way you want it is the image or the way it is today is the image?

  • Yes, the shape I want is the image

  • I did not understand very well, lacked your jquery code and css

1 answer

1


Basically, just add the following properties to the CSS:

.mask-loading {
      position: absolute;
      top: 0px;
      left: 0px;
      z-index: 1000;
      background-color: #000;
      opacity: 0.5;
      width: 100%;
      height: 100%;
}

This way you are adding color, opacity, size and position to your div.

Below is an example of how it works. It is not your model, but it is possible to understand what you want.

$('#loader').click(function() {
  $('.mask-loading').show();

  setTimeout(function() {
    $('.mask-loading').hide();
  }, 5000);
});
.mask-loading {
  position: absolute;
  top: 0px;
  left: 0px;
  z-index: 100;
  background-color: #000;
  opacity: 0.5;
  width: 100%;
  height: 100%;
  display: none;
}
img {
  top: 500px;
  z-index: 1000;
  background-color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="mask-loading">
  <figure>
    <img src="http://www.mtlexs.com/images/reload.gif" alt="carregando...">
    <figcaption class="loading-text"></figcaption>
  </figure>
</div>

<div>
  sua página aqui
</div>

<button id="loader">Loader</button>

There are several ways to do what you want. However, as I don’t know your code, I added a way that I think should work for you.

  • Perfect @Randrade, but the opacity is catching the spinner tbm, know how to solve? I tried to edit directly in the class with a ! Important and nothing..

  • @João Colocar the z-index spinner larger than div. I edited the answer by adding a soft background in the spinner.

  • in mine did not work. Continue with the same opacity

  • @John Unfortunately, you can’t help without knowing how your CSS is doing. You can try adding !importante; to see. However, it would be better if you post the full code to see what is causing the conflict.

  • Follow https://jsfiddle.net/9m12L0rc/

  • @João This is because the gif you chose has the white background. Take your example with another gif who will understand.

  • Got it @Randrade, thank you very much!

Show 2 more comments

Browser other questions tagged

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