8000 优化键盘事件处理 · HashCoding/boxbot@901b567 · GitHub
[go: up one dir, main page]

Skip to content

Commit 901b567

Browse files
committed
优化键盘事件处理
1 parent 7238faf commit 901b567

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Application.prototype.hotkey = function (event) {
9191
if (event.target.tagName == 'BODY') {
9292
var direction = {37: LEFT, 38: TOP, 39: RIGHT, 40: BOTTOM}[event.keyCode]
9393
if (typeof direction != 'undefined') {
94+
event.preventDefault()
9495
if (direction == this.boxbot.bot.getCurrentDirection()) {
9596
this.boxbot.run(this.boxbot.go).then(null, function (e) {
9697
console.log(e)
@@ -99,10 +100,9 @@ Application.prototype.hotkey = function (event) {
99100
this.boxbot.run(this.boxbot.turn, [direction])
100101
}
101102
} else if (event.keyCode == 32) {
103+
event.preventDefault()
102104
this.boxbot.run(this.boxbot.build)
103105
}
104-
//防止操作键盘上下键时,导致整个页面的上下移动
105-
event.preventDefault()
106106
}
107107
}
108108

0 commit comments

Comments
 (0)
0