Skip to content

Instantly share code, notes, and snippets.

@AndrewHaine
Created May 3, 2021 15:08
Show Gist options
  • Save AndrewHaine/686e84e105453f2bb5523f01b45f631d to your computer and use it in GitHub Desktop.
Save AndrewHaine/686e84e105453f2bb5523f01b45f631d to your computer and use it in GitHub Desktop.
GlideJS AutoHeight functionality
/**
* 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