so I came across this snippet below which is fantastic at changing my pages within a div. However, I'm scratching my head on how I can do the following:
- make it so it fades in a CSS preloader e.g.preload (https://projects.lukehaas.me/css-loaders/)
- it then to show this preloader for x amount of seconds
- Then for the preloader to fade out and show the content.
If anyone out there can help me point me in the right direction, a big thank you in advance.
$(function() {
if(Modernizr.history){
var newHash = "",
$mainContent = $("#main-content"),
$pageWrap = $("#page-wrap"),
baseHeight = 0,
$el;
$pageWrap.height($pageWrap.height());
baseHeight = $pageWrap.height() - $mainContent.height();
$("nav").delegate("a", "click", function() {
_link = $(this).attr("href");
history.pushState(null, null, _link);
loadContent(_link);
return false;
});
function loadContent(href){
$mainContent
.find("#guts")
.fadeOut(2000, function() {
$mainContent.hide().load(href + " #guts", function() {
$mainContent.fadeIn(1000, function() {
$pageWrap.animate({
});
});
$("nav a").removeClass("current");
console.log(href);
$("nav a[href$="+href+"]").addClass("current");
});
});
}
$(window).bind('popstate', function(){
_link = location.pathname.replace(/^.*[\\\/]/, '');
loadContent(_link);
});
}
});