我使用WordPress和我的內容是這樣的添加鍵盤上的箭頭導航自定義JS
<div class="image-wrap"><a class="ajax-load-next" href="http://linktopage.com/2/"><img src="blah1.jpg" alt=""/></a></div><!--nextpage-->
<div class="image-wrap"><a class="ajax-load-next" href="http://linktopage.com/3/"><img src="blahab.jpg" alt=""/></a></div><!--nextpage-->
<div class="image-wrap"><a class="ajax-load-next" href="http://linktopage.com/4/"><img src="blahco.jpg" alt=""/></a></div><!--nextpage-->
<div class="image-wrap"><a class="ajax-load-next" href="http://linktopage.com/5/"><img src="blahneat.jpg" alt=""/></a></div>
我有當用戶點擊了圖片加載下一個圖像的自定義JavaScript。現在我想將左邊的&右鍵盤箭頭導航添加到這個腳本中,我不知道如何實現它,因爲我不熟悉JavaScript。
$('body').on('click', '.image-wrap', function(e) { // listen for 'click' on our '.image-wrap' element
e.preventDefault(); // Prevents default behavior on the a element
$.ajax({
url: $(this).find('a').attr('href'), // the url we are fetching by ajax
success: function (response) {
newImg = $(response).find('.image-wrap').html(), // get the new href link and image from the response, contained in div.image-wrap
$('div.image-wrap').html(newImg); // set the new html for our inner div
}
}).fail(function (data) {
if (window.console && window.console.log) {
console.log(data); // log failure to console
}
});
});
編輯: 按下右箭頭鍵我希望它點擊AJAX鏈接,裏面像包裝的div應加載下一個圖像。如果按下左箭頭鍵,它應該返回到前一個圖像。任何想法如何做到這一點?
還不清楚。箭頭鍵應該操作哪個圖像包裝div?你有四個。 –
在wordpress上,它會在頁面上只顯示一個圖像 - 包裝div,導致<! - nextpage - >標籤將這些div分成多個頁面。因此,箭頭鍵應該專注於頁面上的一個圖像換行div – TravelWhere