Skip to content

Instantly share code, notes, and snippets.

@sirneb
Created June 11, 2011 05:26
Show Gist options
  • Save sirneb/1020279 to your computer and use it in GitHub Desktop.
Save sirneb/1020279 to your computer and use it in GitHub Desktop.
$('div.toc a').bind('click', function(event) {
go_to_top();
$.get($(this).attr("href"), $(this).serialize(), null, "script");
if ( history.pushState ){ // trying to use this clause to check pushState compability
event.preventDefault();
history.pushState(null, "", this.href); // pushes the URL to link bar
}
return false;
})
// UI enhancement script that makes sure the user isn't too far away from the top of the page, will scroll up if so
function go_to_top(){
// alert($('#content_title').offset().top);
if(window.pageYOffset > $('#content_title').offset().top){
$('html, body').animate({'scrollTop':$('#content_title').offset().top}, 'fast');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment