2013-04-22 35 views
0

是否有人知道顯示縮略圖的任何現有Javascript(或jquery),以及何時單擊主圖像更新的縮略圖。更新主圖像的縮略圖圖庫

除此之外,關鍵要求是當您單擊另一個縮略圖時,當前顯示的圖像淡出,然後新圖像淡入(使其淡入淡出)。

我期待這樣做來推廣照明演示,所以褪色是關鍵部分。

由於提前,

(希望這是在正確的部分,並已正確地問!很抱歉,如果不是的話,我是新來的這個)

+0

這聽起來很簡單,讓你自己 – Bill 2013-04-22 14:49:59

+0

嗨比利,我已經採取了一打預製腳本,並試圖增加淡入淡出效果,但無濟於事。這是我得到的壁櫥:http://jsfiddle.net/Lr9KK/ - 我無法從頭開始編寫Javascript,但是我可以編輯它。謝謝你的幫助。 – 2013-04-22 14:51:46

+0

http://stackoverflow.com/questions/1977557/jquery-fade-to-new-image應該可以幫到你 – DrColossos 2013-04-22 14:59:10

回答

1

我創造了這個,我希望它能幫助:

http://jsfiddle.net/K7ANs/

$('.thumbnail').on('click',function(){ 
    $('#imageWrap').append('<img src="' + $(this).attr('src') + '" class="next" />'); 
    $('#imageWrap .active').fadeOut(1000); 
    $('#imageWrap .next').fadeIn(1000, function(){ 
     $('#imageWrap .active').remove(); 
     $(this).addClass('active'); 
    }); 
}); 

更新:

要停止用戶單擊另一個縮略圖直到當前動畫完成,我只是將函數包裝在if語句中,以檢查圖像是否爲動畫。我還可以這樣,如果有兩個圖像(如動畫中有兩個,當它完成了其他被刪除)

$('.thumbnail').on('click',function(){ 
    if (!$('#imageWrap .active').is(':animated')){ 
     $('#imageWrap').append('<img src="' + $(this).attr('src') + '" class="next" />'); 
     $('#imageWrap .active').fadeOut(1000, function(){ 
      $(this).remove(); // I moved this from the other function because targeting $(this) is more accurate. 
     }); 
     $('#imageWrap .next').fadeIn(1000, function(){ 
      $(this).addClass('active'); 
     }); 
    } 
}); 

Here is an updated jsFiddle

來源(S)

檢查jQuery API - :animated selector
jQuery API - .is()
jQuery API - .fadeIn()
jQuery API - .fadeOut()

+0

嗨比利,那太棒了。一個輕微的問題,當你快速點擊幾張縮略圖(煩人的人會!)它打破並且空白。有什麼辦法阻止他們能夠點擊另一個縮略圖,直到完全加載? – 2013-04-23 08:28:26

+0

是的,給我一分鐘我會更新:) – Bill 2013-04-23 11:25:01