我使用 html 、 css 和 jquery 創(chuàng)建了一個(gè)手風(fēng)琴我添加了相關(guān)的 css 來(lái)更改活動(dòng)手風(fēng)琴標(biāo)題的背景和不透明度,效果很好但問(wèn)題是 - 在我第二次點(diǎn)擊手風(fēng)琴標(biāo)題以將其最小化后,它仍然在活動(dòng)標(biāo)題屬性中繼承為了使它像其他不活動(dòng)的手風(fēng)琴標(biāo)題一樣正常,除了已經(jīng)將其最小化之外,我還必須點(diǎn)擊手風(fēng)琴之外的任何地方我希望有人可以調(diào)整代碼來(lái)解決這個(gè)問(wèn)題JSBIN]連結(jié)這里展示與代碼一起輸出代碼包含在下面的片段中$(document).ready(function () { function close_accordion_section() { $('.accordion .accordion-section-title').removeClass('active'); $('.accordion .accordion-section-content').slideUp(300).removeClass('open'); } $('.accordion-section-title').click(function (e) { // Grab current anchor value var currentAttrValue = $(this).attr('href'); if ($(e.target).is('.active')) { close_accordion_section(); } else { close_accordion_section(); // Add active class to section title $(this).addClass('active'); // Open up the hidden content panel $('.accordion ' + currentAttrValue).slideDown(300).addClass('open'); } e.preventDefault(); });});/*----- Accordion -----*/.accordion,.accordion * { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box;}.accordion { overflow: hidden; box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.25); border-radius: 3px; background: #f7f7f7;}/*----- Section Titles -----*/.accordion-section-title { width: 100%; padding: 15px; display: inline-block; border-bottom: 1px solid #1a1a1a; background: #333; transition: all linear 0.15s; /* Type */ font-size: 1.200em; text-shadow: 0px 1px 0px #1a1a1a; color: #fff;}.accordion-section-title.active,.accordion-section-title:hover { background: #4c4c4c; text-decoration: none; opacity: 0.5;}.accordion-section:last-child .accordion-section-title { border-bottom: none;}/*----- Section Content -----*/.accordion-section-content { padding: 15px; display: none;}<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
Accordion 的 Active Title 屬性無(wú)法正常工作
三國(guó)紛爭(zhēng)
2021-10-14 17:34:47