我正在建造一個手風琴,其中包括幾個孩子,並在點擊時顯示打開/關閉圖標。手風琴展開摺疊圖標問題
我遇到的問題是圖標。一次展開和摺疊很好,但是當您打開多個項目時,圖標開始出現奇怪的動作,並在應該加上時顯示錯誤。
我已經試驗過每個if else語句,但現在運氣還不錯。
我還提供了一個鏈接到我CodePen
$(document).ready(function(){
$('.pub-accordion-content').hide();
$('#pub-accordion').find('.pub-accordion-toggle').click(function(){
var $this = $(this);
//Toggle icon
$this.toggleClass("open");
//Expand or collapse this panel
$this.next().slideToggle('fast')
//Hide the other panels
$(".pub-accordion-content").not($this.next()).slideUp('fast');
});
});
#pub-accordion {
padding: 24px;
}
#pub-accordion h4:first-child {
border-top: 1px solid #ccc;
}
#pub-accordion h4 {
border-bottom: 1px solid #ccc;
color: #00539f;
font-size: 1.6em;
margin: 0;
padding: 16px 0 16px 33px;
cursor: pointer;
}
#pub-accordion .closed {
background: url(http://www.dcholloway.co.uk/codepen/primary-collapse-icon.png) no-repeat 0 13px;
}
#pub-accordion .open {
background: url(http://www.dcholloway.co.uk/codepen/primary-expand-icon.png) no-repeat 0 13px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Size Guide - - - - - - - - - - - - - - - - -->
<div class="row row__im impage--no-margin">
<div class="page">
<div class="row">
<div class="s-100 m1-100 m2-100 l-100">
<div id="pub-accordion">
<h4 class="pub-accordion-toggle closed">Boys size guide</h4>
<div class="pub-accordion-content default">
<p>Lorem ipsum dolor sit amet mauris eu turpis.</p>
</div>
<h4 class="pub-accordion-toggle closed">Girls size guide</h4>
<div class="pub-accordion-content">
<p>Lorem ipsum dolor sit amet mauris eu turpis.</p>
</div>
<h4 class="pub-accordion-toggle closed">Boys plus fit size guide</h4>
<div class="pub-accordion-content">
<p>Vivamus facilisisnibh scelerisque laoreet.</p>
</div>
<h4 class="pub-accordion-toggle closed">Girls plus fit size guide</h4>
<div class="pub-accordion-content">
<p>Vivamus facilisisnibh scelerisque laoreet.</p>
</div>
</div>
</div>
</div>
</div>
</div>
非常感謝您的幫助傑拉德和保羅 – David