4 ms·
Did this (using jquery): var loadingLayer = { step: 0, add: function(){ this.step += 1; //didn't know how to call checkState() auto
by enapupe 15y ago
Did this (using jquery):
var loadingLayer = {
step: 0,
add: function(){
this.step += 1;
//didn't know how to call checkState() automatically after any other call
this.checkState();
}, remove: function(){
this.step -= 1;
this.step < 0 && (this.step=0);
this.checkState();
}, clear: function(){
this.step = 0;
this.checkState();
}, checkState: function(){
if (this.step === 0){
$("body").removeClass("loading");
} else {
$("body").addClass("loading");
}
}
};
$(document).ajaxStart( function(){
loadingLayer.add();
});
$(document).ajaxComplete(function(){
loadingLayer.remove();
});
I know the JS is uggly but i'm not an js expert (it works).
- enapupe 15y agoLive demo: http://jsfiddle.net/NXqe5/ http://jsfiddle.net/NXqe5/