25 June 2023

To prevent scrolling with the spacebar using the keydown event instead of keyup, you can listen for the spacebar key using JavaScript and prevent the default behavior of the key if it is pressed down.

Source code viewer
  1. document.addEventListener('keydown', function(event) {
  2. if (event.code === 'Space') {
  3. event.preventDefault();
  4. }
  5. });
Programming Language: Javascript