淡出jquery图片库

时间:2012-05-16 09:55:57

标签: jquery fade

这是我现在的代码。

http://workshop.rs/demo/gallery-in-4-lines/

$('#thumbs').delegate('img','click', function(){
$('#largeImage').attr('src',$(this).attr('src').replace('thumb','large'));
});

但我想淡化这个例子的方式?

http://www.ak-solutions.de/demos/fader/

从图片到下一张图片更慢?

我试过这段代码,但这不是正确的。

$('#thumbs').delegate('img', 'click', function() {
$('#panel').attr('src', $(this).attr('src')).hide().fadeIn(1000);
});

1 个答案:

答案 0 :(得分:1)

jsBin demo

$('.thumbs').on('click','img', function(){
        var $thisPanel = $(this).parents('.gallery').find('.panel');
        var clone = $(this).clone().hide();
        clone.appendTo($thisPanel);
        $thisPanel.find('img').eq(0).fadeTo(600,0,function(){
           $(this).remove();
        });
        clone.fadeTo(600,1);  
        $('.description').html($(this).attr('alt'));
});

修改后的CSS:

  .thumbs { padding-top: 10px; overflow: hidden;}
    .thumbs img, .panel img {
     border: 1px solid gray;
     padding: 4px;
     background-color: white;
     cursor: pointer;
    }
  .panel img{
    position:absolute;
  }
    .thumbs img {
     float: left;
     margin-right: 3px;
    width:100px;
    }
    .description {
     background: black;
     color: white;
     position: absolute;
     z-index:2;
     bottom: 0;
     padding: 10px 20px;
     width: 525px;
     margin: 5px;
    }
相关问题