2013-04-22 67 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