Created
February 1, 2021 11:28
-
-
Save guillaumegarcia13/589ad82c5b14b432b8fc8d0e255a555e to your computer and use it in GitHub Desktop.
Elementor - Custom external links for Image Carousel
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
//--------------------------------------------------------------------------------- | |
// Set custom links for your Elementor Carousel Image | |
// Usage: | |
// o set the list of links (comma-separated) in the Custom URL | |
// o add a new HTML widget in the page and copy the JS below | |
// o (optional) you might copy the CSS as well | |
// | |
// Author: Guillaume GARCIA | |
// Date : 1-feb-2021 | |
// | |
//---------------------------------------------------------------------------------- | |
</script> | |
// Set the right external link for the right image | |
const fixCarouselLinks = function() { | |
let links = document.querySelectorAll('.swiper-wrapper .swiper-slide a[href]'); | |
const FULL_URLS = links[0].getAttribute('href').split(','); | |
links.forEach(link => { | |
let index = link.parentNode.getAttribute('data-swiper-slide-index'); | |
let externalLink = FULL_URLS[index] && FULL_URLS[index].split('/undefined'); // ELEMENTOR?! | |
externalLink && link.setAttribute('href', externalLink); | |
}); | |
}; | |
document.addEventListener('DOMContentLoaded', () => { | |
setTimeout(fixCarouselLinks, 0); | |
}); | |
</script> | |
<style> | |
figure.swiper-slide-inner > img { | |
height: 150px; | |
width: 150px; | |
object-fit: contain; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment