accordion switch
P粉517090748
P粉517090748 2023-09-03 21:16:38
0
1
346

The accordion effect I edited on Codepen worked fine. However, when clicking on multiple questions, I want the previous answers to close while the current answer is open. Is there any way to achieve this?

Codepen link here

Also, when using Font Awesome 4.7.0, the following Unicode displays normally.

(f055 & f056) Unicodes

But after switching to Font Awesome 5.14.5, Unicode no longer works.

P粉517090748
P粉517090748

reply all (1)
P粉066224086

Turn off other buttons and cycle through all buttons withinonclickagain. For the font, replacefont-family: "FontAwesome";withfont-family: "Font Awesome\ 5 Free";

const accordionBtns = document.querySelectorAll(".accordion"); accordionBtns.forEach((accordion) => { accordion.onclick = function() { this.classList.toggle("is-open"); let content = this.nextElementSibling; if (content.style.maxHeight) { content.style.maxHeight = null; } else { // add this line accordionBtns.forEach(acc => acc.nextElementSibling.style.maxHeight = null) content.style.maxHeight = content.scrollHeight + "px"; } }; });
.faq-container { width: 80%; max-width: 600px; margin: 50px auto; } button.accordion { width: 100%; background: #C0C0C0; border: none; outline: none; text-align: left; padding: 15px 20px; font-size: 18px; font-weight: bold; color: #4169E1; cursor: pointer; transition: background-color 2.2s linear; } button.accordion:after { content: "\f055"; font-family: "Font Awesome\ 5 Free"; font-size: 18px; float: right; } button.accordion.is-open:after { content: "\f056"; } button.accordion:hover, button.accordion.is-open { color: #FFF; background: #4169E1; /*border-left: 2px solid #C0C0C0; border-right: 2px solid #C0C0C0; border-top: 2px solid #C0C0C0; border-bottom: 2px solid #C0C0C0;*/ } .accordion-content { font-family: Arial; font-weight: bold; color: #663399; background: #FFF; border-left: 2px solid #C0C0C0; border-right: 2px solid #C0C0C0; border-bottom: 2px solid #C0C0C0; padding: 0 20px; max-height: 0; overflow: hidden; transition: max-height 0.2s ease-in-out; }
 

FAQ Accordion

On The Date That We Select.
On The Date That We Select.

Because We Chose To.

At The Place That We Select.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!