Created
September 27, 2011 13:28
-
-
Save makeusabrew/1245039 to your computer and use it in GitHub Desktop.
keypress nav
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
<script> | |
$(function() { | |
// let's make a bespoke handler for a keypress, so we can potentially | |
// do something like animate the A or whatever | |
$("li.prev a, li.next a").bind('keynav', function(e) { | |
// $(this) is the A element at this point | |
// for now, just go to the href, but we could do more fun stuff here | |
window.location = $(this).attr("href"); | |
}); | |
// bind the keydown event and listen out for left and right keys only | |
$(window).keydown(function(e) { | |
switch (e.which) { | |
case 37: // left | |
$("li.prev a").trigger("keynav"); | |
break; | |
case 39: // right | |
$("li.next a").trigger("keynav"); | |
break; | |
default: | |
// nada | |
break; | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment