【问题标题】:Accordion Reopens手风琴重新开放
【发布时间】:2015-10-06 23:41:32
【问题描述】:

我正在制作一个手风琴,您可以在 http://jsfiddle.net/ybgjub4g/ 看到它

每个手风琴在点击手风琴时关闭并且当前手风琴打开,唯一的问题是当我单击当前打开的手风琴关闭它然后它关闭并重新打开时,我不知道为什么。

$(document).ready(function() {
    (function($) {
        var allPanels = $('.accordion > span').hide();
        $('.accordion > .question').click(function() {
            allPanels.slideUp();
            $(this).next('span').slideDown();
            $('.accordion.current').removeClass('current');
            $(this).parent().addClass('current');
            return false;
        });
    }
    )(jQuery);
});

【问题讨论】:

    标签: jquery accordion


    【解决方案1】:

    你可以试试这个解决方案

    $(".question").click(function(){
    
        if(false == $(this).next().is(':visible')) {
            $('span').slideUp(300);
        }
        $(this).next().slideToggle(300);
    });
    

    http://jsfiddle.net/ybgjub4g/5/

    【讨论】:

      【解决方案2】:

      这是DEMO

      js:

      $(document).ready(function() {
      (function($) {
          var allPanels = $('.accordion > span');
      
          $('.accordion > .question').click(function() {
              var _this = this;
      
              $('.current > span ').slideUp()
      
              if(!$(_this).parent().hasClass('current')){
                $(_this).next('span').slideDown();
                 $('.accordion.current').removeClass('current');
                 $(_this).parent().addClass('current');
              }else{
      
                 $(_this).parent().removeClass('current');
              }
      
      
      
      
              return false;
          });
      }
      )(jQuery);
      });
      

      【讨论】:

      • 否,如果您单击打开的标题,它会关闭并自动重新打开。
      • 对不起,我正在处理它
      【解决方案3】:

      固定使用:

      $(document).ready(function() {
          $(".accordion span").hide();
          $(".accordion .question").click(function(){
              if(false == $(this).next().is(':visible')) {
                  $('span').slideUp(300);
              }
              $(this).next().slideToggle(300);
              $('.accordion.current').removeClass('current');
              $(this).parent().addClass('current');
          });
      });
      

      【讨论】:

        猜你喜欢
        • 2022-06-27
        • 1970-01-01
        • 2017-01-21
        • 2015-02-13
        • 1970-01-01
        • 1970-01-01
        • 2015-04-04
        • 2019-07-23
        • 1970-01-01
        相关资源
        最近更新 更多