Skip to content

Instantly share code, notes, and snippets.

@Fastidious
Last active October 4, 2017 11:42
Show Gist options
  • Save Fastidious/1cd42e69c23c61f6b1d2 to your computer and use it in GitHub Desktop.
Save Fastidious/1cd42e69c23c61f6b1d2 to your computer and use it in GitHub Desktop.
JS previous and next

Navigate with arrow keys, mustly to be used on a static content generator, like Jekyll or Hugo:

<script>
$(document).keydown(function(e){
  if (e.keyCode == 37 && $(".prev").length == 1) {
    e.preventDefault();
    window.location.href = $(".prev").attr("href");
  } else if (e.keyCode == 39 && $(".next").length == 1) {
    e.preventDefault();
    window.location.href = $(".next").attr("href");
  }
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment