简体   繁体   English

响应手风琴问题

[英]Responsive tabs to accordion issue

I'm in the process of modifying a responsive tabs to accordion, please see the jsfiddle 我正在修改手风琴的响应式标签,请参阅jsfiddle

When the current 'active' tab is clicked it hides which I understand is what it is meant to do in the code, however I would like it if this does not happen and doesn't hide. 单击当前的“活动”选项卡时,它隐藏了我所理解的代码中要执行的操作,但是,如果这种情况没有发生并且没有隐藏,我希望这样做。 Here is the current javascript: 这是当前的javascript:

$('#nav').children('li').first().children('a').addClass('active')
        .next().addClass('is-open').show();

$('#nav').on('click', 'li > a', function() {

      if (!$(this).hasClass('active')) {

        $('#nav .is-open').removeClass('is-open').hide();
        $(this).next().toggleClass('is-open').toggle();

        $('#nav').find('.active').removeClass('active');
        $(this).addClass('active');
      } else {
        $('#nav .is-open').removeClass('is-open').hide();
        $(this).removeClass('active');
      }
});

It's basically just applying classes dependent on what is clicked and what is currently active or not. 基本上,它只是根据所单击的内容以及当前是否处于活动状态来应用类。 I guess I need to change the logic of this? 我想我需要改变这种逻辑吗?

If what I understood is correct that you want to stop hiding the active div when clicked again. 如果我理解的是正确的,则您想在再次单击时停止隐藏活动的div。 Just remove the else part... 只需删除其他部分...

$('#nav').children('li').first().children('a').addClass('active')
        .next().addClass('is-open').show();

$('#nav').on('click', 'li > a', function() {

      if (!$(this).hasClass('active')) {

        $('#nav .is-open').removeClass('is-open').hide();
        $(this).next().toggleClass('is-open').toggle();

        $('#nav').find('.active').removeClass('active');
        $(this).addClass('active');
      }
});

Check this Fiddle 检查这个小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM