Created
July 14, 2021 18:45
-
-
Save peterkarn/615cd5b7f9d8fa0977f4de12b9d001b6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const sliders = document.querySelectorAll('.slider__wrapper'); | |
if (sliders.length > 0) { | |
sliders.forEach((slider, i) => { | |
const items = slider.querySelectorAll('.work-item'); | |
items.forEach(item => { | |
const linkWrapper = document.createElement('a'); | |
const image = item.querySelector('img'); | |
const description = image.getAttribute('alt'); | |
const galleryLink = image.getAttribute('src').trim(); | |
linkWrapper.setAttribute('data-fancybox', `gallery--${i}`); | |
linkWrapper.setAttribute('href', galleryLink); | |
linkWrapper.innerHTML = image.outerHTML; | |
if (description) { | |
linkWrapper.setAttribute('data-caption', description); | |
} | |
item.prepend(linkWrapper); | |
image.remove(); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment