Use fadeOut()
jQuery function for document
or "html"
:
$(document).fadeOut();
or
$("html").fadeOut();
After reading your comments I understand you want to fade out the page when clicking a link.
Don't use $(window).unload
but detect the click events on the links and set the location manually preventing the default browser behavior.
// delegate all clicks on "a" tag (links)
$(document).on("click", "a", function () {
// get the href attribute
var newUrl = $(this).attr("href");
// veryfy if the new url exists or is a hash
if (!newUrl || newUrl[0] === "#") {
// set that hash
location.hash = newUrl;
return;
}
// now, fadeout the html (whole page)
$("html").fadeOut(function () {
// when the animation is complete, set the new location
location = newUrl;
});
// prevent the default browser behavior.
return false;
});