Skip to content

Instantly share code, notes, and snippets.

@aaronpk
Last active May 19, 2016 08:29
Show Gist options
  • Save aaronpk/6336291 to your computer and use it in GitHub Desktop.
Save aaronpk/6336291 to your computer and use it in GitHub Desktop.
$(document).keydown(function(e){
// Ignore the keypress if any meta keys were pressed along with the arrows
if(e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) return;
// Left arrow
if(e.keyCode == 37) {
// Find a rel="prev" link on the page
if($("a[rel='prev']").length > 0){
// Highlight it briefly
$("a[rel='prev']").addClass('hover');
// Navigate to the page
window.location.href = $("a[rel='prev']").attr('href');
}
return false;
}
// Right arrow
if(e.keyCode == 39) {
// Find a rel="next" link on the page
if($("a[rel='next']").length > 0){
// Highlight it briefly
$("a[rel='next']").addClass('hover');
// Navigate to the page
window.location.href = $("a[rel='next']").attr('href');
}
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment