Skip to content

Instantly share code, notes, and snippets.

@mbmccormick
Created November 7, 2011 15:45
Show Gist options
  • Select an option

  • Save mbmccormick/1345316 to your computer and use it in GitHub Desktop.

Select an option

Save mbmccormick/1345316 to your computer and use it in GitHub Desktop.
Handle browser's back button, dynamically load content, transition to replace content
$(window).bind("popstate", function() {
$("body").css("cursor", "progress");
$(".main").after("<section class='left'></section>");
$(".left").load(location.pathname + " .main>*", function() {
if ($(".left h1").text().length > 0)
document.title = "Matt McCormick - " + $(".left h1").text();
else
document.title = "Matt McCormick";
$("body").css("cursor", "auto");
$(".main").animate({ left: widthB + "px"}, function() {
$(".main").remove();
});
$(".left").show();
$(".left").animate({ left: widthA + "px"}, function(){
$(".left").addClass("main");
$(".left").removeClass("left");
});
render();
$("html, body").animate({ scrollTop:0 }, 0);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment