Skip to content

Instantly share code, notes, and snippets.

@timarney
Last active August 29, 2015 14:05
Show Gist options
  • Save timarney/ac3702cbdb3fc37548d2 to your computer and use it in GitHub Desktop.
Save timarney/ac3702cbdb3fc37548d2 to your computer and use it in GitHub Desktop.
//note:offset & speed could be setup as globals
/**
on page load or ajax update:
if(window.location.hash) {
// Fragment exists
scroll(window.location.hash,100,500);
}
direct:
scroll('#id3',100,750)
*/
function scroll(anchor,offset,speed){
$('html, body').animate({ // animate both for cross browser support
scrollTop:$(anchor).position().top - offset
}, speed);
}
// Scroll down to content
$('a.anchor-click').click( function(evt) {
evt.preventDefault();
scroll('#id3',100,750);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment