Tumblr风格的键盘导航 [英] Tumblr Style Keyboard Navigation
问题描述
当您在Tumblr中转到仪表板时,您可以使用键盘在Feed之间来回切换。 ←转到较新的帖子,→转到较旧的帖子。 b
$ b
有人可以帮我弄清楚如何做到这一点。
好的,你要做的是为你的文档元素设置一个keyup事件监听器,读取用户按下的哪个键,然后在键码与您的左键或右键的代码相匹配时执行动作。
左键的键码是37.右键所以你要设置的左键的监听器是这样的:
document.onkeyup = function(e ){
if(e.keyCode == 37){//leftkey。
//你的代码
}
if(e.keyCode == 39){//rightkey。
//您的代码
}
}
I don't know much about how it works. My guess is JavaScript, but anyway.
When you go to your dashboard in Tumblr you can go back and forth between pages in your feed with your keyboard. ← to go forward to newer posts and → to go to older posts.
Can someone help me figure out how they do this.
Well, what you have do is set up a "keyup" event listener for your document element that reads which key your user pressed, then execute an action if the keycode matches the code for your left or right keys.
The "left" key's keycode is 37. the right is 39. So the listener for the "left" key you would set up is this:
document.onkeyup = function(e){
if (e.keyCode == 37) { //"left" key.
//your code
}
if (e.keyCode == 39) { //"right" key.
//your code
}
}
这篇关于Tumblr风格的键盘导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!