你需要真正消失模態在
CSS:
/* Start by setting display:none to make this hidden.
Then we position it in relation to the viewport window
with position:fixed. Width, height, top and left speak
speak for themselves. Background we set to 80% white with
our animation centered, and no-repeating */
.modal {
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;
}
/* When the body has the loading class, we turn
the scrollbar off with overflow:hidden */
body.loading {
overflow: hidden;
}
的Javascript:
$(document).ajaxStart(function() {
$("body").addClass("loading");
$('.modal').fadeIn(500);
});
$(document).ajaxStop(function() {
$("body").removeClass("loading");
$('.modal').fadeOut(500);
});
// Initiates an AJAX request on click
$(document).on("click", function() {
$.post("/mockjax");
});
// http://code.appendto.com/plugins/jquery-mockjax
$.mockjax({
url: '/mockjax',
responseTime: 2000
});
Here's the fiddle.
請參閱http://stackoverflow.com/questions/1248542/jquery-animate-with-css-class-only-without-explicit-styles – noj 2013-03-28 09:38:50