Last active
January 3, 2017 13:06
-
-
Save erikpantzar/89d6ec28a6cd5290f217c0ee19c5466a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default accordion; | |
function accordion(arrayOfAccordions = []) { | |
for(let i = 0; i<arrayOfAccordions.length; i++) { | |
arrayOfAccordions[i].addEventListener('click', (el) => { | |
if(el.target.classList.contains('js-accordion-toggler')) { | |
el.target.parentNode.classList.toggle('accordion__item--expanded'); | |
} | |
return false; | |
}); | |
} | |
} | |
/* | |
Given following markup | |
<ul class="accordion"> | |
<li className="accordion__item"> | |
<a class="js-accordion-toggler"> | |
// TOGGLER CONTENT | |
</a> | |
<div class="accordion__content"> | |
// CONTENT HERE | |
</div> | |
</li> | |
</ul> | |
<style> | |
.accordion__content { | |
display: none; | |
} | |
.accordion__item--expanded .accordion__content { | |
display: block; | |
} | |
</style> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updaterade efter dina kommentarer