Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loading Spinner - always keep in the middle of the screen even while scrolling the page

<div id="Dvloading" style="float: left;">
        <i id="loadingSpinner" class="icon-spinner icon-spin blue" style="margin-left: 50%; position:absolute ; margin-top: 25%; z-index: 1000; font-size: 800%;"></i>
</div>

It is the code for showing a loading graphic while page is getting loading. It shows above a grid view. When the grid consist of large number of rows, when I scroll down the page, I can't see the loading graphic . But when I go to the top of the screen I can see the loading graphic. How I keep it always in the middle of the screen even while scrolling the page?

Please help me.

like image 364
Samadhi Sankalani Avatar asked Jul 06 '15 04:07

Samadhi Sankalani


People also ask

How do I keep the loader in the middle of the screen?

HTML file before your code: <body> <div class="loader"> HTML file after your code: </div> </body> CSS file before your code: body { position: relative; /* parent */ } .

How do you show loading in HTML?

Step 1: Add a background with a spinner gif on top of the page, then remove them when everything is loaded. Step 2: Add a little script right after the opening body tag to start displaying the load/splash screen. Save this answer.


1 Answers

I went through my old answers to see if I could add something that is more modern. In my newer solution you do not need to specify the height or the width. Its a more generic solution.

.center {
   position: fixed;
   top: 50%;
   left: 50%;
   transform: translate(-50%, -50%);
}

Try this:

.centered {
  position: fixed;
  top: 50%;
  left: 50%;
  margin-top: -50px; //Half of the height of the loading graphic
  margin-left: -50px; //Half of the width of the loading graphic
}
like image 186
Nerdkowski Avatar answered Oct 18 '22 09:10

Nerdkowski