Repository navigation
[Help]: Carousel with vertical axis, autoplay and autoheight issue #1371
Replies: 1 comment
|
There are three separate problems in the snippet. First, Second, a vertical Embla carousel needs an explicit height on the slide container. The current Third, remove A reduced version would look like this: .embla__viewport {
overflow: hidden;
height: var(--current-slide-height);
transition: height 0.35s cubic-bezier(0.25, 1, 0.5, 1);
}
.embla__container {
display: flex;
flex-direction: column;
height: var(--current-slide-height);
}
.embla__slide {
flex: 0 0 auto;
width: 100%;
}
.slide__inner {
height: auto;
}const roots = document.querySelectorAll('.js-slider-rotate')
roots.forEach((root) => {
const viewport = root.querySelector('.js-slider-viewport')
const slides = [...viewport.querySelectorAll('.embla__slide')]
const setHeight = (index) => {
const content = slides[index]?.querySelector('.slide__inner')
if (content) {
root.style.setProperty(
'--current-slide-height',
`${content.scrollHeight}px`,
)
}
}
// Embla must see a real vertical view size during initialization.
setHeight(0)
const autoplay = EmblaCarouselAutoplay({
playOnInit: false,
delay: 1000,
stopOnInteraction: false,
})
const api = EmblaCarousel(
viewport,
{ axis: 'y', loop: true },
[autoplay],
)
const syncHeight = () => setHeight(api.selectedScrollSnap())
api.on('select', syncHeight)
api.on('reInit', syncHeight)
autoplay.play()
})
The stack trace is another clue: it comes from |
Uh oh!
There was an error while loading. Please reload this page.
Summary
I have multiple carousels with the vertical Y axis, autoheight and autoplay. By the fact the autoheight plugin only works for X axis, I'm trying to achieve on my own the autoheight feature by calculating the height of current index slide, creating a CSS variable and applying it to the viewport node.
The autoplay doesn't work neither the slider.
Any help would be much appreciated.
Thank you.
HTML
CSS
JAVASCRIPT
If applicable, which variants of Embla Carousel are relevant to this question?
Additional information
CodeSandbox example
No response
All reactions