Skip to content

Instantly share code, notes, and snippets.

@Lysindr
Created August 28, 2018 06:18
Show Gist options
  • Save Lysindr/9022b251e6617b6f009d71403ebaee5b to your computer and use it in GitHub Desktop.
Save Lysindr/9022b251e6617b6f009d71403ebaee5b to your computer and use it in GitHub Desktop.
Scroll top with stoping animation if user scroll manualy when animation in progress
// Scroll to top
/*
* When you click and animation start, if you scroll with mouse, keybord hotkeys in same moment - animation will stop.
/*
$(".scroll-top-class").click(function(e) {
e.preventDefault();
$('html, body').on("scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove", function(){
$('html, body').stop();
});
$('html, body').animate({ scrollTop: $("#top").offset().top }, 1000, function(){
$('html, body').off("scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove");
});
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment