0

我有这个非常基本的标签块:

$('.tabbed-section .panel').hide();
$('.tabbed-section .panel:first').show();
$('.tabbed-section .tabs li:first').addClass('active');
$('.tabbed-section .tabs li a').click(function () {
    $('.tabbed-section .tabs li').removeClass('active');
    $(this).parent().addClass('active');
    var currentTab = $(this).attr('href');
    var tab_id = $(this).attr('href');
    $(this).closest('#hero').attr('class', 'clear ' + tab_id.replace('#', ''));
    $('.tabbed-section .panel').hide();
    $(currentTab).show();
    return false;
});

..效果很好,但是当活动选项卡更改时,我可以添加淡入淡出效果吗?我认为它有一个插件(innerfade),但我想尽可能避免使用另一个插件。

另外,上面的jQuery可以进一步压缩吗?

谢谢你的帮助!

4

2 回答 2

1

这个怎么样?

$('.tabbed-section')
  .find('.panel').hide().end()
  .find('.panel:first').show().end()
  .find('.tabs li:first').addClass('active').end()
  .find('.tabs li a').click( function() {
    var el = $(this);
    $('.tabbed-section .tabs li').removeClass('active');
    el.parent().addClass('active');
    var currentTab = el.attr('href');
    el.closest('#hero').attr('class', 'clear ' + currentTab.replace('#', ''));
    $('.tabbed-section .panel').fadeOut( 'fast', function() {
      $(currentTab).fadeIn('fast');
    } );
    return false;
  } );
于 2010-01-04T12:08:19.747 回答
1

代替

$('.tabbed-section .panel').hide();
$(currentTab).show();

$('.tabbed-section .panel').fadeOut();
$(currentTab).fadeIn();

?

于 2010-01-04T12:08:51.837 回答