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