Created
December 26, 2018 15:10
-
-
Save onuro/af10a10c644c7198c536bec7d2c685e2 to your computer and use it in GitHub Desktop.
Page Preload with FadeIn/FadeOut
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! 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