1

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?

  • 1
    Referring to the way of make it stop when pressing ESC, take a look to this post maybe you will find usefull: https://stackoverflow.com/questions/18522864/disable-scroll-down-when-spacebar-is-pressed-on-firefox – Kalamarico Oct 06 '17 at 22:48
  • 1
    About the uniform movement, take a look to this and search "linear" string: http://api.jquery.com/animate/ you should do the same – Kalamarico Oct 06 '17 at 22:51

0 Answers0