Skip to content

Instantly share code, notes, and snippets.

@ckhatton
Last active August 29, 2015 14:11
Show Gist options
  • Save ckhatton/26e2d03ee8159ea3e7c8 to your computer and use it in GitHub Desktop.
Save ckhatton/26e2d03ee8159ea3e7c8 to your computer and use it in GitHub Desktop.
A scroll-to function. Detects if a manual scroll has occurred during the animation, and stops, to prevent a glitchy clash of actions.
function scrollTo(element, within) {
$(within).bind('mousedown DOMMouseScroll mousewheel', function(){
$(this).stop();
});
$(within).animate({
scrollTop: Math.ceil($(element).position().top)
}, 1500, "easeOutQuart", function(){
$(this).unbind('mousedown DOMMouseScroll mousewheel');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment