Skip to content

Instantly share code, notes, and snippets.

@onuro
Created December 26, 2018 15:10
Show Gist options
  • Save onuro/af10a10c644c7198c536bec7d2c685e2 to your computer and use it in GitHub Desktop.
Save onuro/af10a10c644c7198c536bec7d2c685e2 to your computer and use it in GitHub Desktop.
Page Preload with FadeIn/FadeOut
/*! Fades out the whole page when clicking links */
$('a').click(function(e) {
e.preventDefault();
newLocation = this.href;
$('body').fadeOut('slow', newpage);
});
function newpage() {
window.location = newLocation;
}
//When page is fade out, it can be handy to fade in the new page:
$(document).ready(function(){
/*! Fades in whole page on load */
$('body').css('display', 'none');
$('body').fadeIn(500);
});
/*! There´s only one problem: When you are clicking the back-button in your browser,
you will come to a page that already is faded out. This is because the browser remembers the "fading out",
and it doesn't seem to forget. To avoid this, use this code:
Reloads page on every visit */
function Reload() {
try {
var headElement = document.getElementsByTagName("head")[0];
if (headElement && headElement.innerHTML)
headElement.innerHTML += "<meta http-equiv=\"refresh\" content=\"1\">";
}
catch (e) {}
}
/*! The code above does not work in mobile safari. To force mobile safari to reload the page one time,
simply add these lines of code:
Reloads on every visit in mobile safari */
if ((/iphone|ipod|ipad.*os 5/gi).test(navigator.appVersion)) {
window.onpageshow = function(evt) {
if (evt.persisted) {
document.body.style.display = "none";
location.reload();
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment