Ever uploaded an image or iniated another timeful(slow) process on a webpage? Some sites appear to fade out the whole window while a small loading bar appears. [caption id=“attachment_62” align=“aligncenter” width=“300” caption=“Loading Bar translucent overlay”][/caption] This not only clearly indicates to users that the server is working in the background, but it is a great way to block the impatient click happy users as well. Its a pretty straightforward effect done with javascript and css. CakePHP users can let Cake handle the JS. The critical part is using CSS to create a translucent block that we can overlay on the page.
//for cakephp users
image('ajax-loader.gif'); ?>
//plain html
![](ajax-loader.gif)
/the basics, and works for FF/ #LoadingDiv{ margin:0px 0px 0px 0px; position:fixed; height: 100%; z-index:9999; padding-top:200px; padding-left:50px; width:100%; clear:none; background:url(/img/transbg.png); /background-color:#666666; border:1px solid #000000;/ } /IE will need an ‘adjustment’/
The CSS above allows the div with the id LoadingDiv to lay on top of any other elements on the page. Its like when your teacher use to lay a spare piece of paper over a transparency to block the answers from shining through. Yes, that was a reference to overheads ;)
Note: those using CakePHP should first read this article in the bakery on advanced ajax pagination.
var ldiv = document.getElementById(‘LoadingDiv’); ldiv.style.display=‘block’; /Do your ajax calls, sorting or laoding, etc./ ldiv.style.display = ‘none’;
Those who are using CakePHP 1.2 undoubtedly know about its awesome pagination abilities. Well it can use ajax to complete the task, and we can assign our cool new blockout div as the progress indicator.
$paginator->options(
array('update'=>'PPaging',
'url'=>array('controller'=>'Posts', 'action'=>$this->action,$project_id),
'indicator' => 'LoadingDiv'));
Note: I tried to make this organized and clear, but we all think differently. So if you don’t understand anything, please comment below and I will work to dispel any confusion.