Skip to content

Instantly share code, notes, and snippets.

@Spellhammer
Created January 19, 2022 20:02
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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