如果有人讀這篇文章想要一個不同的方法,仍然使用JQuery fadeIn
,Im在該代碼下面發佈。
Here你可以找到它的小提琴。
這裏的JavaScript部分
//At the start will show the first image
$('#fullimage img.fullimage:first-child').fadeIn();
//Keep track of the image currently being visualized
var curr = $('#fullimage img.fullimage:first-child');
$('#next').on('click', function() {
//Hide Current Image
curr.hide();
//Find Next Image
var next = curr.next();
//If theres no next image (is the last img), go back to first
if (next.length == 0) next = $('#fullimage img:first');
//Fade In
next.fadeIn();
//Save in curr the current Image
curr = next;
return false;
});
$('#prev').on('click', function() {
curr.hide();
var prev = curr.prev();
if (prev.length == 0) prev = $('#fullimage img:last');
prev.fadeIn();
curr = prev;
return false;
});
這裏的HTML部分
<div id="fullimage">
<img class="fullimage" src="http://i.imgur.com/RHhXG.jpg" />
<img class="fullimage" src="http://i.imgur.com/p1L2e.jpg" />
<img class="fullimage" src="http://i.imgur.com/NsrI0.jpg" />
<img class="fullimage" src="http://i.imgur.com/Ww6EU.jpg" />
</div>
<a href="#"><label id="prev">previous</label></a>
<a href="#"><label id="next">next</label></a>
你是什麼試圖做什麼?上一頁和下一頁按鈕可以瀏覽圖像? –
對於你發佈的代碼,你需要知道幾件事情。 'prev()'是遍歷樹的jquery方法。如果你想返回,你可以使用'prev()'。但是這僅僅是不夠的,當你處於第一個位置時,如果你按回去,你想要走到最後。所以你可以使用'$('#fullimage img:last')。fadeIn();'。像[這](http://jsfiddle.net/r7t6G/)。現在,通過這兩種代碼,您可以合併並創建所需的下一個/上一個按鈕。 – wendelbsilva
請發佈您的代碼修改並告訴我們出了什麼問題。 – showdev