【问题标题】:Accordion (Shopify) how to default to all closed手风琴(Shopify)如何默认全部关闭
【发布时间】:2014-10-05 13:19:01
【问题描述】:

我在 shopify 中有一个手风琴,但是当您加载页面时,第一个“标题”是打开的。我希望默认情况下全部关闭,对于我的生活,我无法让它工作,所以非常感谢您的帮助!

不管怎样,现在的代码如下:

   $('.accordion.headings').each(function() {
  return $(this).add($(this).next('.accordion.content')).wrapAll("<div class='accordion-wrapper'/>");
});
$('.accordion.headings li').wrapInner('<div class="trigger"></div>');
$('.accordion.headings li .trigger').append('<div class="bg"></div>');
$('.accordion-wrapper').each(function() {
  var accordion_content, accordion_heading;
  accordion_heading = $(this).find('.accordion.headings > li');
  accordion_content = $(this).find('.accordion.content > li');
  accordion_heading.first().addClass('active');
  accordion_content.each(function(index) {
    var content;
    content = $('<div class="content">' + $(this).html() + '</div>');
    return content.appendTo(accordion_heading.eq(index));
  });
  accordion_content.remove();
  $(this).find('.content').first().show();
  return $(this).find('.trigger').on("click", function() {
    var panels, this_panel;
    panels = $(this).closest(".accordion").find('.content');
    this_panel = $(this).closest("li").find(".content");
    panels.not(this_panel).slideUp(200);
    this_panel.slideDown(200, function() {
      if (general_scroll_to_active_item) {
        return $('html, body').animate({
          scrollTop: this_panel.offset().top - 100
        });
      }
    });
    $(this).closest(".accordion").find("li").removeClass("active");
    return $(this).closest("li").addClass("false");
  });
});

提前致谢, 秒。

【问题讨论】:

    标签: jquery accordion shopify


    【解决方案1】:

    我一直在开发一个内置相同功能的 shopify 网站。如果您删除此处的第一行,您会发现手风琴在页面加载时关闭。

    $(".faqs-container .faq-singular:first-child").addClass("active").children(".faq-answer").slideDown(); //Remove this line if you dont want the first item to be opened automatically.
    $(".faq-question").on("click", function(){
    if( $(this).parent().hasClass("active") ){
      $(this).next().slideUp();
      $(this).parent().removeClass("active");
    }
    else{
      $(".faq-answer").slideUp();
      $(".faq-singular").removeClass("active");
      $(this).parent().addClass("active");
      $(this).next().slideDown();
    }
    

    【讨论】:

      猜你喜欢
      • 2015-03-15
      • 2012-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-12
      相关资源
      最近更新 更多