帮助创造类似手风琴的风格 - jquery

时间:2014-05-15 15:49:46

标签: javascript jquery

我目前正在实施一组类似于手风琴的风格的标签。

到目前为止,这是我的代码......

http://codepen.io/anon/pen/uqBnH

在选择其他人时,我无法关闭其他人。

我的jQuery代码......

$(function(){

 $('.panel').hide();
  $('.mobtabs').click(function(){
    $(this).next().toggle();        
  });
 });

非常感谢任何帮助。

3 个答案:

答案 0 :(得分:1)

您可以使用:

$(function () {
    $('.panel').hide();
    $('.mobtabs').click(function () {
        var nextPanel = $(this).next();
        $('.panel').not(nextPanel).hide();
        nextPanel.toggle();
    });
});

<强> Fiddle Demo

答案 1 :(得分:1)

进行以下更改(我添加了滑动) -

$('.panel').hide();
$('.mobtabs').click(function(){
    $('.mobtabs').not( $(this) ).next().slideUp(); // close them all
    $(this).next().slideToggle(); // slide open (or closed if it applies) this tab       
});

答案 2 :(得分:1)

只需关闭其他人:

$(function () {
    $('.panel').hide();
    $('.mobtabs').click(function () {
        $('.mobtabs').not($(this)).next().hide();
        $(this).next().toggle();
    });
});

<强> jsFiddle example