Last active
May 19, 2016 08:29
-
-
Save aaronpk/6336291 to your computer and use it in GitHub Desktop.
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
$(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