Created
May 3, 2021 15:08
-
-
Save AndrewHaine/686e84e105453f2bb5523f01b45f631d to your computer and use it in GitHub Desktop.
GlideJS AutoHeight functionality
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
/** | |
* glideInstance here is the instance of Glide (created via const glideInstance = new Glide(...)) | |
* sliderElement here is the top-level container element, used for searching for glide elements within | |
*/ | |
glideInstance.on(['mount.after', 'run.after'], () => _glideHandleHeight(sliderElement)); | |
/** | |
* @param {HTMLElement} slider | |
*/ | |
const _glideHandleHeight = slider => { | |
const activeSlide = slider.querySelector('.glide__slide--active'); | |
const activeSlideHeight = activeSlide ? activeSlide.offsetHeight : 0; | |
const glideTrack = slider.querySelector('.glide__track'); | |
const glideTrackHeight = glideTrack ? glideTrack.offsetHeight : 0; | |
if (activeSlideHeight !== glideTrackHeight) { | |
glideTrack.style.height = `${activeSlideHeight}px`; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment