Using in html body
overflow: hidden
I managed to control the scroll flow of a webpage. Is it possible to also prevent users Page Up, Page Down, Up and Down arrow keys from scroll functioning?
Using in html body
overflow: hidden
I managed to control the scroll flow of a webpage. Is it possible to also prevent users Page Up, Page Down, Up and Down arrow keys from scroll functioning?
Use preventDefault()
:
window.onkeydown=function(e){
if(e.keycode==33 || e.keycode==34 || e.keycode==38 || e.keycode==40){
e.preventDefault();
}
}
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;
});
37 - left 38 - up 39 - right 40 - down
$(document).keydown(function(e){
if(e.which>=36 && e.which<40){
e.preventDefault();
}
});
DEMO: FIDDLE