【问题标题】:Gallery with thumbnails that update a main image带有更新主图像的缩略图的画廊
【发布时间】:2014-01-30 06:55:48
【问题描述】:

是否有人知道任何现有的显示缩略图的 Javascript(或 jquery),当您单击缩略图时,主图像会更新。

除此之外,关键要求是当您单击另一个缩略图时,当前显示的图像淡出,然后新图像淡入(因此它们交叉淡入淡出)。

我希望这样做是为了宣传照明演示,所以褪色是关键部分。

提前致谢,

(希望这是在正确的部分并且已被正确询问!抱歉,如果不是,我是新手)

【问题讨论】:

标签: javascript jquery


【解决方案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

来源

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

【讨论】:

  • 嗨,比利,这太棒了。一个小问题,当您快速单击几个缩略图时(会惹恼人们!),它会中断并变为空白。有什么办法可以阻止他们点击另一个缩略图直到它完全加载?
猜你喜欢
  • 1970-01-01
  • 2013-04-20
  • 2018-04-25
  • 1970-01-01
  • 1970-01-01
  • 2012-01-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多