I've got the following function which retrieves a .php file's contents and displays it in a div. The retrieval part works great, but i would like to show a spinner for e.g. 1 second.
Here's my JQuery function:
function f(par){
$("#load").show();
$.ajax({url: par + ".php",
success: function(result){
$("#info").html(result);
$("#info").css("top", Math.max(0, (($(window).height() - $("#info").outerHeight()) / 2) + $(window).scrollTop()) + "px");
$("#info").css("left", Math.max(0, (($(window).width() - $("#info").outerWidth()) / 2) + $(window).scrollLeft()) + "px");
$("#info").delay(1000).show(0);
}});
$("#load").hide();
};
Load here is the div with the spinner in it and info displays well.. the retrieved info! The master plan is to delay (because the retrieval takes no time at all) the show(0) function, to let the spinner run at least 1 second.
The css is as followed (from How can I create a "Please Wait, Loading..." animation using jQuery?):
#load {
display: none;
position: fixed;
z-index: 1000;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: rgba( 255, 255, 255, .8 )
url('http://sampsonresume.com/labs/pIkfp.gif')
50% 50%
no-repeat;
}
#info{
display: none;
position: fixed;
z-index: 500;
height: 40%;
width: 60%;
overflow: auto;
background: rgba(0, 190, 0, .8);
}
I've aso tried to use $(this).addClass("load"); but that didn't work either.
What goes wrong?
Solution:
(for those interested) Thanks to j08691 the solution was quite simple:setTimeout(function() {
$("#info").show();
$("#load").hide();
}, 1500);