如何使箭头键和空格键不强制我的网页? [英] how to make the arrow keys and space bar not force my webpage down?

查看:109
本文介绍了如何使箭头键和空格键不强制我的网页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个游戏,我正在使用箭头键移动和空格键进行拍摄,每当我按下向下键或空格键时它会一直强制下降到网页底部
有任何方式来修改CSS使其专注于游戏div标签而不是滚动???

I built a game and i am using the arrow keys to move and space bar to shoot and it keeps forcing it down to the bottom of the web page every time i hit the down key or space bar is there any way to modify the CSS to make it focus on the game div tag and not scroll???

推荐答案

你没有取消活动。如果它是内联事件,则只需返回false; 。如果用 addEventListener 完成,请调用 事件 .preventDefault()返回false;

You are failing to cancel the event. If it's an inline event, just return false; at the end of it. If it's done with addEventListener, call Event.preventDefault() and return false;.

这篇关于如何使箭头键和空格键不强制我的网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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