按空格键向下滚动页面? [英] Pressing spacebar scrolls page down?

查看:597
本文介绍了按空格键向下滚动页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我甚至不知道要搜索哪些内容才能解决问题。当我按下空格键时,整个页面向上移动(向下滚动):我不希望发生这种情况。我的 body 标签的样式为 overflow:hidden ,如果这与它有关系,没有任何滚动条。我通常很擅长执行初步的故障排除技术,但在这种情况下,我甚至不知道从哪里开始。如何停止这种行为?

I have a problem that I'm not even sure what to search for in order to fix. When I press the spacebar my entire page moves up (scrolls down): I don't want this to happen. My body tag is styled to overflow:hidden, if that has anything to do with it, so the page won't have any scrollbars. I'm usually pretty good at executing the preliminary troubleshooting techniques but in this case I don't even know where to start. How can I stop this behaviour?

其他信息:我正在使用jQuery 1.4.2

Additional information: I am using jQuery 1.4.2

推荐答案

除非你吃掉按键,否则这是大多数浏览器的预期行为。我一直使用它,当它在页面中不起作用时,我非常恼火。

Unless you eat the keypress this is the expected behavior in most browsers. I use it all the time and I get extremely annoyed when it doesn't work in a page.

但是,如果你想吃钥匙......

But if you want to eat the key...

window.onkeydown = function(e) { 
  return !(e.keyCode == 32);
};

这篇关于按空格键向下滚动页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆