javascript 常见问题手风琴

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 常见问题手风琴相关的知识,希望对你有一定的参考价值。

/******  folding FAQ styling  ******/
.fold, .fold * {
    -webkit-box-sizing:border-box; 
    -moz-box-sizing:border-box; 
    box-sizing:border-box;
}
.fold {
    overflow:hidden;
    box-shadow:0px 1px 3px rgba(0,0,0,0.25);
    border-radius:3px;
    background:#f7f7f7;
}
/*----- Section Titles -----*/
.fold-section-title {
    width:100%;
    padding:15px;
    display:inline-block;
    border-bottom:1px solid #1a1a1a;
    background:#0074AA;
    transition:all linear 0.15s;
    /* Type */
    font-size:1.200em;
    text-shadow:0px 1px 0px #1a1a1a;
    color:#fff;
    text-decoration: none;
    font-size:22px;
}
.fold-section-title.active, .fold-section-title:hover {
    background:#cd181e;
    /* Type */
    text-decoration:none;
}
.fold-section:last-child .fold-section-title {
    border-bottom:none;
}
/*----- Section Content -----*/
.fold-section-content {
    padding:15px;
    display:none;
  font-size:16px
}


/*----- Arrow color/hide change (optional) -----*/
.faqarrow {
  color: blue;
}
.showarrow {
  color: red !important;
}
/******  end folding FAQ section  ******/
<!-- to add changability to the arrow  -->

 <span class="faqarrow showarrow"> ▼ </span>  <!-- replace the first arrow with this  -->
  <span class="faqarrow"> ▼ </span>  <!-- replace the rest with this  -->



<!-- MAIN CODE  -->
<div class="fold">
    <div class="fold-section">
        <a class="fold-section-title active" href="#fold-1">Question ▼</a>
        <div id="fold-1" class="fold-section-content open" style="overflow: hidden; display: block;">
            <p>Answeransweransweransweransweransweransweransweranswer</p>
        </div><!--end .fold-section-content-->
    </div><!--end .fold-section-->
</div><!--end .fold-->
<br>
<div class="fold">
    <div class="fold-section">
        <a class="fold-section-title" href="#fold-2">Question ▼</a>
        <div id="fold-2" class="fold-section-content" style="overflow: hidden;">
            <p>Answeransweransweransweransweransweransweransweranswer</p> 
        </div><!--end .fold-section-content-->
    </div><!--end .fold-section-->
</div><!--end .fold2-->
<br>
<div class="fold">
    <div class="fold-section">
        <a class="fold-section-title" href="#fold-3">Question ▼</a>
        <div id="fold-3" class="fold-section-content" style="overflow: hidden;">
            <p>Answeransweransweransweransweransweransweransweranswer</p>
        </div><!--end .fold-section-content-->
    </div><!--end .fold-section-->
</div><!--end .fold3-->
<br>
<div class="fold">
    <div class="fold-section">
        <a class="fold-section-title" href="#fold-4">Question ▼</a>
        <div id="fold-4" class="fold-section-content" style="overflow: hidden;">
            <p>Answeransweransweransweransweransweransweransweranswer</p>
        </div><!--end .fold-section-content-->
    </div><!--end .fold-section-->
</div><!--end .fold3-->
<br>
<div class="fold">
    <div class="fold-section">
        <a class="fold-section-title" href="#fold-5">Question ▼</a>
        <div id="fold-5" class="fold-section-content" style="overflow: hidden;">
            <p>Answeransweransweransweransweransweransweransweranswer</p>
        </div><!--end .fold-section-content-->
    </div><!--end .fold-section-->
</div><!--end .fold3-->
<br>
<div class="fold">
    <div class="fold-section">
        <a class="fold-section-title" href="#fold-6">Question ▼</a>
        <div id="fold-6" class="fold-section-content" style="overflow: hidden;">
            <p>Answeransweransweransweransweransweransweransweranswer</p>
        </div><!--end .fold-section-content-->
    </div><!--end .fold-section-->
</div><!--end .fold3-->
<br>
<div class="fold">
    <div class="fold-section">
        <a class="fold-section-title" href="#fold-7">Question ▼</a>
        <div id="fold-7" class="fold-section-content" style="overflow: hidden;">
            <p>Answeransweransweransweransweransweransweransweranswer</p>
        </div><!--end .fold-section-content-->
    </div><!--end .fold-section-->
</div><!--end .fold3-->
<br>
<div class="fold">
    <div class="fold-section">
        <a class="fold-section-title" href="#fold-8">Question ▼</a>
        <div id="fold-8" class="fold-section-content" style="overflow: hidden;">
            <p>Answeransweransweransweransweransweransweransweranswer</p>
        </div><!--end .fold-section-content-->
    </div><!--end .fold-section-->
</div><!--end .fold3-->
<br>
<div class="fold">
    <div class="fold-section">
        <a class="fold-section-title" href="#fold-9">Question ▼</a>
        <div id="fold-9" class="fold-section-content" style="overflow: hidden;">
            <p>Answeransweransweransweransweransweransweransweranswer</p>
        </div><!--end .fold-section-content-->
    </div><!--end .fold-section-->
</div><!--end .fold3-->
<br>
<div class="fold">
    <div class="fold-section">
        <a class="fold-section-title" href="#fold-10">Question ▼</a>
        <div id="fold-10" class="fold-section-content" style="overflow: hidden;">
            <p>Answeransweransweransweransweransweransweransweranswer</p>
        </div><!--end .fold-section-content-->
    </div><!--end .fold-section-->
</div><!--end .fold3-->
// Folding FAQ
<script>
$(document).ready(function() {
    function close_fold_section() {
        $('.fold .fold-section-title').removeClass('active');
        $('.fold .fold-section-content').slideUp(300).removeClass('open');
    }
    $('.fold-section-title').click(function(e) {
        // Grab current anchor value
        var currentAttrValue = $(this).attr('href');
        if($(e.target).is('.active')) {
            close_fold_section();
        }else {
            close_fold_section();
            // Add active class to section title
            $(this).addClass('active');
            // Open up the hidden content panel
            $('.fold ' + currentAttrValue).slideDown(300).addClass('open'); 
        }
        e.preventDefault();
    });
});
</script>


// Folding FAQ with changing arrows
<script>
  $(document).ready(function() {
    function close_fold_section() {
        $('.fold .fold-section-title').removeClass('active');
        $('.fold .fold-section-content').slideUp(300).removeClass('open');
        $('.fold .fold-section-title .faqarrow').removeClass('showarrow');
    }

    $('.fold-section-title').click(function(e) {
        // Grab current anchor value
        var currentAttrValue = $(this).attr('href');
        if($(e.target).is('.active')) {
            close_fold_section();
        }else {
            close_fold_section();
            // Add active class to section title
            $(this).addClass('active');
            // Open up the hidden content panel
            $('.fold ' + currentAttrValue).slideDown(300).addClass('open');
           $(this).children("span").addClass('showarrow');
          console.log(this);
        }
        e.preventDefault();
    });
});
</script>

以上是关于javascript 常见问题手风琴的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript Accordion - 自动滚动到打开的手风琴顶部

Javascript手风琴 - 折叠除活动之外的所有打开实例

JavaScript 手风琴与YUI javascript库

使用 jquery 或 javascript 为父子属性创建手风琴式下拉菜单

Bootstrap手风琴Javascript在另一张卡关闭时打开一张卡

javascript 手风琴 - VE友好