有誰知道如何通過幻燈片緩存「緩存」幻燈片?如果我點擊箭頭10次,那麼有10張幻燈片會滑過,有沒有辦法阻止它?或者,如果您點擊反向箭頭取消另一個「緩存」點擊,停止js幻燈片緩存點擊次數
http://www.switchonthecode.com/tutorials/jquery-creating-a-slideshow
謝謝!
有誰知道如何通過幻燈片緩存「緩存」幻燈片?如果我點擊箭頭10次,那麼有10張幻燈片會滑過,有沒有辦法阻止它?或者,如果您點擊反向箭頭取消另一個「緩存」點擊,停止js幻燈片緩存點擊次數
http://www.switchonthecode.com/tutorials/jquery-creating-a-slideshow
謝謝!
使用one()函數可能會做你正在尋找的。將代碼調整爲以下內容:
$(document).ready(function(){
// The "one()" function means that this action is disconnected
// from the element once the action occurs. In other words, click
// it twice, and the second one does nothing.
$("#slideshow-previous").one("click", showPreviousSlide);
$("#slideshow-next").one("click", showNextSlide);
...
});
但是僅僅這樣做還不夠。動畫完成後,我們必須再次掛接事件處理程序。使用的動畫()的回調函數:
function updateContentHolder()
{
...
$("#slideshow-scroller").animate({scrollLeft: scrollAmount}, 1000, function() {
$("#slideshow-previous").one("click", showPreviousSlide);
$("#slideshow-next").one("click", showNextSlide);
});
}
正如有人指出,在評論這有多次安裝showPreviousSlide和showNextSlide的問題沒有按下按鈕爲準。你可以通過做更多的工作來彌補這一點:
function showPreviousSlide()
{
currentSlide--;
updateContentHolder($(this).attr("id"), showPreviousSlide);
updateButtons();
}
function showNextSlide()
{
currentSlide++;
updateContentHolder($(this).attr("id"), showNextSlide);
updateButtons();
}
...
function updateContentHolder(id, callback)
{
...
$("#slideshow-scroller").animate({scrollLeft: scrollAmount}, 1000, function() {
$("#" + id).one("click", callback);
});
}
這會雙擊你沒有點擊的那個點擊嗎?既然你在兩個方法上都調用'one',但是隻有一個被點擊後再調用它們呢? – 2011-06-15 20:54:37
輝煌 - 這正是我所需要的 - 本網站及其成員非常棒 - 非常感謝所有的幫助! – Dave 2011-06-15 21:20:37
@kingjiv,很好。更新了答案。 – riwalk 2011-06-15 22:13:12