0
How to move a div in javascript?
So i'm making a snake clone as a project and my current block is trying to move the div (snake) with the arrow keys. I've tried the event.keyCode method but that didn't work.
6 ответов
+ 3
document.onkeydown = checkKey;
function checkKey(e) {
e = e || window.event; if (e.keyCode == '38') { // up arrow } else if (e.keyCode == '40') { // down arrow } else if (e.keyCode == '37') { // left arrow } else if (e.keyCode == '39') { // right arrow }
(got it from stackoverflow from a quick google search)
+ 3
@Fbia34, I tip you to do it on jquery :P
do you rly want to do it with JS only ?
+ 1
Emperor Bob I looked on stack overflow and found nothing, maybe I should've look for more than 2 minutes
+ 1
just do a quick search on google that is "js detect arrow keypress"
+ 1
NoxFly ドリアン I don't know jQuery so that's why
0
But thanks though