键盘导航以加载页面 [英] Keyboard Navigation to load pages
本文介绍了键盘导航以加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有使用左右箭头键加载下一页的快速方法? 到目前为止,我的解决方案是:
is there a quick way to use the right and left arrow keys to load the next page? My solution so far is:
$(document).ready(function () {
$("a.transition").click(function (event) {
event.preventDefault();
linkLocation = this.href;
$("body").fadeOut(20, redirectPage);
});
$("a.transitionB").click(function (event) {
event.preventDefault();
linkLocation = this.href;
$("body").fadeOut(20, redirectPage);
});
function redirectPage() {
window.location = linkLocation;
}
});
具有2个不可见的链接层.但是我需要一些东西来控制过渡,而无需单击页面,而是使用箭头按钮.
with 2 invisible link layers. But i need something to control the transition without clicking in the page, but to use the arrow buttons.
谢谢您的帮助.
推荐答案
尝试一下(不同的浏览器==不同的键码):
Try this (different browser == different keycodes):
function redirectPage(href) {
window.location = href;
}
function onKey(e) {
var key = e.keyCode ? e.keyCode : e.which;
if (key == 37 || key == 26) {
e.preventDefault();
$("a.transition").click();
} else if (key == 39 || key == 27) {
e.preventDefault();
$("a.transitionB").click();
}
}
$(document).ready(function () {
$(document).keypress(onKey);
$("a.transition, a.transitionB").click(function (event) {
event.preventDefault();
$("body").fadeOut(20, function() {redirectPage(this.href)});
});
});
这篇关于键盘导航以加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文