Skip to content

Instantly share code, notes, and snippets.

@jenswittmann
Created March 4, 2021 10:47
Show Gist options
  • Save jenswittmann/43b9f8489a699022664d72d814c94c98 to your computer and use it in GitHub Desktop.
Save jenswittmann/43b9f8489a699022664d72d814c94c98 to your computer and use it in GitHub Desktop.
Accordion for WordPress Lay Theme
Button Link: #akkordeon_1
HTML Klasse: akkordeon_1
<!-- 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>
/* Custom CSS */
[class*="akkordeon_"] {
display: none !important;
}
.akkordeon--active {
display: block !important;
}
@iciio
Copy link

iciio commented Mar 4, 2021

<3!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment