Last active
August 29, 2015 13:56
-
-
Save xat/8882979 to your computer and use it in GitHub Desktop.
scrollTo
This file contains 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
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