Created
February 2, 2017 08:28
-
-
Save josephdicdican/ae279f44a4344f4e0d270e4a6cad7972 to your computer and use it in GitHub Desktop.
jQuery Keydown - Arrow Keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var goLeft = function() { | |
console.log('to left'); | |
}; | |
var goRight = function() { | |
console.log('to right'); | |
}; | |
var goUp = function() { | |
console.log('to up'); | |
}; | |
var goDown = function() { | |
console.log('to down'); | |
}; | |
// requires jquery | |
$(document).on('keydown',function(e){ | |
var act={37:goLeft, 38:goUp, 39:goRight, 40:goDown}; | |
if(act[e.which]) var a=new act[e.which]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment