0
如何使用JavaScript为Tumblr主题创建箭头键导航?使用JavaScript的Tumblr箭头键导航
我正在尝试编写一些JavaScript以允许Tumblr主题的用户使用left
和right
箭头键来导航页面。
我已经成功地获得基本的概念工作:
document.onkeydown = function(event) {
event = event || window.event;
var key = event.keyCode;
var currentPage = {CurrentPage};
// left arrow key
if (key == 37) {
var previousPage = currentPage - 1;
window.location.href = "/page/" + previousPage;
}
// right arrow key
if (key == 39) {
var nextPage = currentPage + 1;
window.location.href = "/page/" + nextPage;
}
};
这跑进用户能够超越最后一页,可能(我不是很确定)的永久工作的问题页面。但是,为网址使用{PreviousPage}
和{NextPage}
变量要容易得多,但由于某些原因,我无法让它们在JavaScript中工作。即使我用JS(即{JSPreviousPage}
和{JSNextPage}
)作为它们的前缀,它们仍然毫无结果,尽管HTML中的变量工作正常。
谢谢。完全超过了这个想法。 – Spencer 2013-03-27 03:50:37