Skip to content

Instantly share code, notes, and snippets.

@josephdicdican
Created February 2, 2017 08:28
Show Gist options
  • Save josephdicdican/ae279f44a4344f4e0d270e4a6cad7972 to your computer and use it in GitHub Desktop.
Save josephdicdican/ae279f44a4344f4e0d270e4a6cad7972 to your computer and use it in GitHub Desktop.
jQuery Keydown - Arrow Keys
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