Created
March 4, 2021 10:47
-
-
Save jenswittmann/43b9f8489a699022664d72d814c94c98 to your computer and use it in GitHub Desktop.
Accordion for WordPress Lay Theme
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
Button Link: #akkordeon_1 | |
HTML Klasse: akkordeon_1 |
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
<!-- Custom HTML at bottom --> | |
<script> | |
window.laytheme.on( "newpageshown", function( layoutObj, type, obj ) { | |
var akkordeonActiveClassName = "akkordeon--active", | |
akkordeonBtnEls = document.querySelectorAll("[href^='#akkordeon_']"); | |
akkordeonBtnEls.forEach( function( akkordeonBtnEl, i ) { | |
var akkordeonChildClass = akkordeonBtnEl.getAttribute("href").replace("#", ""), | |
akkordeonChildEls = document.querySelectorAll( "." + akkordeonChildClass ); | |
akkordeonBtnEl.addEventListener( "click", function( e ) { | |
akkordeonChildEls.forEach( function( akkordeonChildEl, i ) { | |
if (akkordeonChildEl.classList.contains(akkordeonActiveClassName)) { | |
akkordeonChildEl.classList.remove(akkordeonActiveClassName); | |
} else { | |
akkordeonChildEl.classList.add(akkordeonActiveClassName); | |
} | |
} ); | |
} ); | |
} ); | |
} ); | |
</script> |
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
/* Custom CSS */ | |
[class*="akkordeon_"] { | |
display: none !important; | |
} | |
.akkordeon--active { | |
display: block !important; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
<3!