I want a button that, when clicked, makes page scroll smoothly down to 4000px. But I also want this scrolling to stop when user presses ESC.
Here's my code:
$('#scroll-fast').on('click', function() {
$('html,body').animate({scrollTop: 4000 }, 160000);
});
$(document).keyup(function(e) {
if (e.keyCode == 27) {
$('html,body').stop(true);
}
});
Problem #1) Scrolling movement isn't uniform: it starts slow and then accelerates.
Problem #2) I can't find a way to make it stop by pressing ESC.
Any help?