Tumblr 风格键盘导航
我不太了解它是如何工作的。我的猜测是 JavaScript,但无论如何。
当您转到 Tumblr 中的仪表板时,您可以使用键盘在提要的页面之间来回切换。 ← 转到较新的帖子,→ 转到较旧的帖子。
有人可以帮我弄清楚他们是如何做到这一点的吗?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么,您要做的就是为文档元素设置一个“keyup”事件侦听器,该事件侦听器读取用户按下的键,然后在键代码与左键或右键的代码匹配时执行操作。
“左”键的键码是 37。右键是 39。所以您要设置的“左”键的监听器是这样的:
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:
想通了:
Figured it out: