Is it possible to prevent users Page Up, Page Down

2019-07-07 00:18发布

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?

3条回答
Animai°情兽
2楼-- · 2019-07-07 00:44

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

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

DEMO: FIDDLE

查看更多
相关推荐>>
3楼-- · 2019-07-07 00:52

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;
});
查看更多
该账号已被封号
4楼-- · 2019-07-07 01:04

Use preventDefault():

window.onkeydown=function(e){
   if(e.keycode==33 || e.keycode==34 || e.keycode==38 || e.keycode==40){
       e.preventDefault();
   }
}
查看更多
登录 后发表回答