我使用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