Created
November 14, 2013 23:25
-
-
Save maxxcrawford/7476264 to your computer and use it in GitHub Desktop.
Smooth animate/scroll to snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(".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