Ajax Loader 1.0

Created Thursday 25th of September 2008 by Andreas Lagerkvist
Copyright © 2008 Andreas Lagerkvist (andreaslagerkvist.com)

What it Does

Use this plug-in when you want to inform your visitors that a certain part of your page is currently loading. The plug-in adds a faded 'loading-div' on top of the selected element(s). The div is of course completely stylable.

How to Use

jQuery('#contact').ajaxLoader(); would add the overlay on top of the #contact-element.

When you want to remove the loader simply run jQuery('#contact').ajaxLoaderRemove();

Example

I should start loading after a couple of seconds, then load for a couple more and then stop loading only to start again after a couple of seconds. And so on.

Example Code

HTML

<div id="jquery-ajax-loader-example">
I should start loading after a couple of secondsthen load for a couple more and then stop loading only to start again after a couple of seconds. And so on.
</
div>

JS

setInterval(function () {
    
jQuery('#jquery-ajax-loader-example').ajaxLoader();
    
setTimeout(function () {
        
jQuery('#jquery-ajax-loader-example').ajaxLoaderRemove();
    }, 
2000);
}, 
4000);

Source Code

jQuery.fn.ajaxLoader = function (conf) {
    var 
config jQuery.extend({
        
className:        'jquery-ajax-loader'
        
fadeDuration:    500
    
}, conf);

    return 
this.each(function () {
        var 
jQuery(this);

        if (!
this.ajaxLoaderObject) {
            var 
offset t.offset();
            var 
dim = {
                
left:    offset.left
                
top:    offset.top
                
width:    t.outerWidth(), 
                
height:    t.outerHeight()
            };

            
this.ajaxLoaderObject jQuery('<div class="' config.className '"></div>').css({
                
position:    'absolute'
                
left:        dim.left 'px'
                
top:        dim.top 'px',
                
width:        dim.width 'px',
                
height:        dim.height 'px'
            
}).appendTo(document.body).hide();
        }

        
this.ajaxLoaderObject.fadeIn(config.fadeDuration);
    });
};

jQuery.fn.ajaxLoaderRemove = function () {
    return 
this.each(function () {
        if (
this.ajaxLoaderObject) {
            
this.ajaxLoaderObject.fadeOut(500);
        }
    });
};

Download

Plug-in

Requires

blog comments powered by Disqus

Random jQuery Plug-ins

  • Captcha Refresh

    If you use a so called CAPTCHA-image on your site then you can use this plug-in to allow users to click your CAPTCHA in order to generate a new random...

    Details

  • Live Search

    Use this plug-in to turn a normal form-input in to a live ajax search widget. The plug-in displays any HTML you like in the results and the search-res...

    Details

  • Numeric DL

    This tiny plug-in numbers definitions in a definition-list if there are more than one definition for a term. Can be useful for FAQs, actual lists of d...

    Details

More Plug-ins

Recent Comments

Powered by Disqus
Page cached. Loaded in: 0.0169 second(s).
Last DB change: 2012-04-02 11:06:05
Last file change: 2012-04-25 20:30:39
Cache created: 2012-05-18 11:08:15