Skip to content

Instantly share code, notes, and snippets.

@mherod
Created July 17, 2013 14:23
Show Gist options
  • Save mherod/6020990 to your computer and use it in GitHub Desktop.
Save mherod/6020990 to your computer and use it in GitHub Desktop.
Ajax hash navigation with default page switch and transition animation
var container_div = ".container", content_div = ".content", default_hash = "#main";
function anchorRefresh() {
var a = location.hash.substring(1);
$(".active").removeClass("active");
$(content_div).css({opacity:0.5});
$(content_div).load("ajax/" + a + ".html", function() {
$(location.hash).addClass("active");
$(content_div).animate({opacity:1})
})
}
$(window).on("hashchange", function() {
anchorRefresh()
});
"" == location.hash ? location.hash = default_hash : anchorRefresh();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment