Created
April 24, 2014 02:10
-
-
Save jakeauyeung/11239106 to your computer and use it in GitHub Desktop.
用户浏览页面的时候可以使用键盘左右方向键导航到上一篇,下一篇
This file contains hidden or 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
$(function(){ | |
$(document).keydown(function(e) { | |
var url = false; | |
if (e.which == 37 || e.which == 72) { // Left arrow and J | |
{% if page.previous %} | |
url = '{{page.previous.url}}'; | |
{% endif %} | |
} else if (e.which == 39 || e.which == 76) { // Right arrow and K | |
{% if page.next %} | |
url = '{{page.next.url}}'; | |
{% endif %} | |
} | |
if (url) { | |
window.location = url; | |
} | |
} | |
); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment