Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display loading.gif at the center of the screen which has a scrollbar

Tags:

jquery

css

I am trying to display loading.gif/spinning wheel whenever a user clicks the button. I have added a div as below in the master page:

<div id="loadingDiv">     <div>         <h7>Please wait...</h7>     </div> </div> 

This is the css:

#loadingDiv{   position:absolute;   top:0px;   right:0px;   width:100%;   height:100%;   background-color:#666;   background-image:url('ajax-loader.gif');   background-repeat:no-repeat;   background-position:center;   z-index:10000000;   opacity: 0.4;   filter: alpha(opacity=40); /* For IE8 and earlier */ } 

When I try this, the loading.gif is displayed at the center of the page. But as the page is really long , I have to scroll in order to see the loading.gif.

How can I display the loading.gif at the center of the screen which is visible? And if I scroll down, I should see that again at the center of the screen.

like image 725
Vahi Avatar asked Jul 25 '14 17:07

Vahi


1 Answers

Here's the solution. . JS FIDDLE DEMO

HTML

<body> <div class="content">     Long Content Here     <br/>     Click to view loading image. </div> <div id="divLoading">  </div> 

CSS

#divLoading { display : none; } #divLoading.show { display : block; position : fixed; z-index: 100; background-image : url('http://loadinggif.com/images/image-selection/3.gif'); background-color:#666; opacity : 0.4; background-repeat : no-repeat; background-position : center; left : 0; bottom : 0; right : 0; top : 0; } #loadinggif.show { left : 50%; top : 50%; position : absolute; z-index : 101; width : 32px; height : 32px; margin-left : -16px; margin-top : -16px; } div.content { width : 1000px; height : 1000px; } 

jQuery

$(document).ready(function(){ $("div.content").click(function(){     $("div#divLoading").addClass('show'); }); }); 
like image 169
Ankit Singhania Avatar answered Oct 10 '22 13:10

Ankit Singhania