Is it possible to prevent the Up, Down, Down and Down buttons from scrolling from scroll mode?

Usage in html body

overflow: hidden

      

I was able to control the scroll flow of a webpage. Can I also prevent users from scrolling through the pages using the Page Down, Page Up, and Page Down buttons?

+3


source to share


3 answers


Use preventDefault()

:



window.onkeydown=function(e){
   if(e.keycode==33 || e.keycode==34 || e.keycode==38 || e.keycode==40){
       e.preventDefault();
   }
}

      

0


source


This was my solution:



var ar = new Array(33, 34, 38, 40);

$(document).keydown(function (e) {
    var key = e.which;
    if ($.inArray(key, ar) > -1) {
        e.preventDefault();
        return false;
    }
    return true;
});

      

0


source


37 - left 38 - up 39 - right 40 - down

$(document).keydown(function(e){
   if(e.which>=36 && e.which<40){
       e.preventDefault();
   }
});

      

DEMO: FIDDLE

0


source







All Articles