Skip to content

Instantly share code, notes, and snippets.

@maxxcrawford
Created November 14, 2013 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxxcrawford/7476264 to your computer and use it in GitHub Desktop.
Save maxxcrawford/7476264 to your computer and use it in GitHub Desktop.
Smooth animate/scroll to snippet
$(".scroll").click(function(event){
event.preventDefault();
//calculate destination place
var dest=0;
if($(this.hash).offset().top > $(document).height()-$(window).height()){
dest=$(document).height()-$(window).height();
}else{
dest=$(this.hash).offset().top;
}
//go to destination
$('html,body').animate({scrollTop:dest}, 1000,'swing');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment