如何使用箭头键而不是鼠标阻止滚动? [英] How do I prevent scrolling with arrow keys but NOT the mouse?
本文介绍了如何使用箭头键而不是鼠标阻止滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于我正在使用jQuery,因此任何解决方案都可以使用。理想情况下,我想知道两者。
Since I'm using jQuery, any solution via that would work too. Ideally, I'd like to know both, though.
我已经将箭头键绑定到我页面上的另一个函数(使用jQuery),但让它们导致除此之外滚动的页面,会给我带来麻烦。
I already have the arrow keys bound to another function on my page (using jQuery), but having them cause the page to scroll in addition to that, causes me problems.
我可能一次都知道这个,但我不记得了。
I may have known this at one time, but I don't remember it anymore.
推荐答案
添加文档级按键处理程序可以解决问题!
Adding document level keypress handler does the trick!
var ar=new Array(33,34,35,36,37,38,39,40);
$(document).keydown(function(e) {
var key = e.which;
//console.log(key);
//if(key==35 || key == 36 || key == 37 || key == 39)
if($.inArray(key,ar) > -1) {
e.preventDefault();
return false;
}
return true;
});
这篇关于如何使用箭头键而不是鼠标阻止滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文