简体   繁体   English

如何使箭头键和空格键不迫使我的网页向下?

[英]how to make the arrow keys and space bar not force my webpage down?

我制作了一个游戏,并且我使用箭头键移动和空格键进行拍摄,并且每次我按下向下键或空格键时,它都会一直将其压低到网页底部,是否可以将CSS修改为使它专注于游戏div标签而不滚动?

You are failing to cancel the event. 您无法取消活动。 If it's an inline event, just return false; 如果是内联事件,则return false;否则, return false; at the end of it. 在它的结尾。 If it's done with addEventListener , call Event .preventDefault() and return false; 如果使用addEventListener完成,则调用Event .preventDefault()return false; Event .preventDefault()return false; .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何禁用空格键并在网页上输入密钥? - How do I disable use of the space bar and enter keys on my webpage? 如何在反应中使用向上和向下箭头键使下拉菜单工作 - how to make dropdown work using up and down arrow keys in react 如何禁用向上和向下箭头键 - How to disable up and down arrow keys 如何在按“向上”或“向下”箭头键时使Fancybox切换到下一个或上一个画廊? - How can I make Fancybox switch to the next or previous gallery upon pressing the 'up' or 'down' arrow keys? 我如何制作 div 或<li>通过向上/向下箭头键访问</li> - How do I make div or <li> accessible through Up/down arrow keys 在玩游戏时,如何阻止我的网站通过箭头键上下滚动? - How do I stop my website from scrolling up and down with the arrow keys when playing games? 如何向下推网页以适合顶部栏 - how to push webpage down to fit a top bar 用户向下滚动我的网页时,如何删除Chrome地址栏周围的边框 - How to remove the border around the address bar of chrome when the user scrolls down my webpage 当用户在我的网页上向下滚动100像素左右时,淡出图像(向下箭头) - Fade an image out (down-arrow) when a user scrolls 100px or so down my webpage 如何使箭头键始终能够移动我的角色? - How do I make the arrow keys always able to move my character?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM