Skip to content

Instantly share code, notes, and snippets.

@veryrobert
Last active December 20, 2015 04:19
Show Gist options
  • Select an option

  • Save veryrobert/6069967 to your computer and use it in GitHub Desktop.

Select an option

Save veryrobert/6069967 to your computer and use it in GitHub Desktop.
Jquery Load Content and maintain nav
$('#wrapper').hide();
//loads content
function loadContent(url) {
$('#wrapper').load(url).delay(500).fadeIn(500);
}
$(function() {
$('#nav a').on('click', function(e) {
e.preventDefault();
$('#wrapper').fadeOut(500);
var href = $(this).attr("href");
setTimeout(function(){
loadContent(href);
history.pushState({}, '', href);
}, 500);
});
$('#wrapper').on('popstate', function() {
loadContent(location.pathname);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment