public
Last active

  • Download Gist
paging.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
$(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;
}
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.