Skip to content

Instantly share code, notes, and snippets.

@Spellhammer
Created January 19, 2022 20:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Spellhammer/ea9d0804703e78997f0e537d4eb8729b to your computer and use it in GitHub Desktop.
Save Spellhammer/ea9d0804703e78997f0e537d4eb8729b to your computer and use it in GitHub Desktop.
Dynamic Image Accordion JS
var ready = (callback) => {
if (document.readyState != "loading") callback();
else document.addEventListener("DOMContentLoaded", callback);
}
ready(() => {
if(window.angular) return;
document.querySelectorAll('.image-accordion__item:first-child').forEach( first => {
first.classList.add('image-accordion__item--active');
})
})
document.querySelectorAll('.image-accordion__item').forEach( item => {
if( window.angular ) return;
item.addEventListener('click', (event) => {
event.target.parentElement.querySelector('.image-accordion__item--active').classList.remove('image-accordion__item--active');
event.target.classList.add('image-accordion__item--active');
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment