Skip to content

Instantly share code, notes, and snippets.

@xat
Last active August 29, 2015 13:56
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 xat/8882979 to your computer and use it in GitHub Desktop.
Save xat/8882979 to your computer and use it in GitHub Desktop.
scrollTo
var scrollTo = function($target) {
var $body = $('body,html');
var currentOffset = $(window).scrollTop();
var targetOffset = $target.offset().top;
var distance = Math.abs(currentOffset - targetOffset);
if (!$target.length) {
return;
}
$body.animate({
'scrollTop': $target.offset().top
}, distance*0.5);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment