Tumblr风格的键盘导航 [英] Tumblr Style Keyboard Navigation

查看:127
本文介绍了Tumblr风格的键盘导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太了解它是如何工作的。我的猜测是JavaScript,但无论如何。



当您在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆