Hi. I'm trying to make a jquery script that makes the page fade out before leaving it. can anyone help?
+6
A:
I think this would be the least obtrusive way. It simply fades out the page just before unload, regardless of whether the unload is caused by F5, navigating to another page, closing the browser window, or clicking a link.
window.onbeforeunload = function() { $(document.body).fadeOut() }
If you just want it for special links, tho, you could try this:
$('a.withFade').live('click', function() {
var url = $(this).attr('href');
$(document.body).fadeOut('1000', function() {
location.href = url;
});
return false;
});
David Hedlund
2009-11-24 10:18:49
or alternatively, if you want jQuery-ish syntax: `$(window).bind('beforeunload', function() { $(document.body).fadeOut(); });`
Richard Nguyen
2009-11-24 10:24:00
+1 that's a good point, that'd probably be better for browser compatibility as well
David Hedlund
2009-11-24 10:25:47