折叠并展开标签jquery /简单手风琴

时间:2012-07-16 12:19:57

标签: javascript jquery html css accordion

我有关于Accordion标签的查询..

我使用了 Accordion Menu 插件下面的代码我用于页面中的标签。

  [accordions]
  [accordion title ="about"]**Content 1** [/accordion ]
  [accordion title="Home"]**Content 2** [/accordion ]
  [/accordions]

网页如下所示:

enter image description here

我首先想要折叠这两个标签。当点击关于时,它应该展开并显示内容。点击主页后,它应该会崩溃关于标签并展开主页

通过jquery我可以实现这一点,但我不知道下载哪个脚本并使用它..

任何想法? 提前致谢

2 个答案:

答案 0 :(得分:0)

如果您使用jQuery UI Accordion,您可以向手风琴添加简单的事件。

或添加活动:

$( ".selector" ).bind( "accordioncreate", function(event, ui) {
  $( ".selector" ).accordion( "option", "active", -1 )
});

答案 1 :(得分:0)

我有两种不同的简单手风琴方法;第一个是关闭按钮,第二个是悬停触发器。

1)以下是JsFiddle example with close button:

<强> jQuery的:

$('.content').slideUp(400);//reset panels

$('.panel').click(function() {//open
   var takeID = $(this).attr('id');//takes id from clicked ele
   $('#'+takeID+'C').slideDown(400);
                             //show's clicked ele's id macthed div = 1second
});
$('span').click(function() {//close
   var takeID = $(this).attr('id').replace('Close','');
   //strip close from id = 1second
    $('#'+takeID+'C').slideUp(400);//hide clicked close button's panel
});​

<强> HTML:

<div class="panel" id="panel1">panel1</div>
<div id="panel1C">content1
  <span id="panel1Close">X</span>
</div>
<div class="panel" id="panel2">panel2</div>
<div id="panel2C">content2
  <span id="panel2Close">X</span>
</div>
<div class="panel" id="panel3">panel3</div>
<div id="panel3C">content3
  <span id="panel3Close">X</span>
</div>

-------

2)以下是JsFiddle example with hover trigger:

$('.panel').hover(function() {
   var takeID = $(this).attr('id');//takes id from clicked ele
   $('.content').stop(false,true).slideUp(400);//close
   //used stop for prevent conflict
   $('#'+takeID+'C').stop(false,true).slideDown(400);//open
   //show's clicked ele's id macthed div
});​