Skip to content

Instantly share code, notes, and snippets.

@peterkarn
Created July 14, 2021 18:45
Show Gist options
  • Save peterkarn/615cd5b7f9d8fa0977f4de12b9d001b6 to your computer and use it in GitHub Desktop.
Save peterkarn/615cd5b7f9d8fa0977f4de12b9d001b6 to your computer and use it in GitHub Desktop.
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