3

I am trying to remove the feature of scrolling in a page with arrows. In all other posts that I have checked they suggested e.preventDefault() function. I tried it but it was also blocking many default features for arrows that are heavily used in my page. I want just to block the scrolling with arrows and not the default behavior of arrows. What solution do you suggest in this case?

Please don't mark as a duplicate since in all the other posts e.preventDefault() was taken as solution.

Anonymous
  • 31
  • 5

2 Answers2

2

I would suggest playing with document.activeElement and e.preventDefault() when the active element is an input, textarea and so on.

Vitalii Petrychuk
  • 14,035
  • 8
  • 51
  • 55
0
document.addEventListener('keyup', function(e) {
    if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
        e.preventDefault();
        return false;
    }
});