Skip to content

Instantly share code, notes, and snippets.

@KerberosMorphy
Last active September 18, 2019 14:32
Show Gist options
  • Save KerberosMorphy/8cdba398d8c47633d0878daade689548 to your computer and use it in GitHub Desktop.
Save KerberosMorphy/8cdba398d8c47633d0878daade689548 to your computer and use it in GitHub Desktop.
$(document).keydown(function(e) {
switch(e.which) {
case 37: // left
console.log('LEFT');
if($('.prev-link').length && !$('.prev-link.disabled').length) {
var ref = $('h2 a.prev-link')[0]["href"]
window.location.assign(ref);
}
break;
case 39: // right
console.log('RIGHT');
if($('.next-link').length && !$('.next-link.disabled').length) {
var ref = $('h2 a.next-link')[0]["href"]
window.location.assign(ref);
}
break;
default: return; // exit this handler for other keys
}
e.preventDefault(); // prevent the default action (scroll / move caret)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment