-
-
Save Spellhammer/ea9d0804703e78997f0e537d4eb8729b to your computer and use it in GitHub Desktop.
Dynamic Image Accordion JS
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
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