[Help]: "stopOnInteraction: false" failing to re-enable autoplay after interaction #866
-
SummaryI am using vanilla JavaScript alongside my Drupal 10 installation and, for whatever reason, setting the I have enqueued the following libraries.
A minimal example of the markup. <div class="hero">
<div class="hero__items">
<div class="hero__item">
<div class="hero__media">
<img loading="lazy" src="/image1.jpg" width="2500" height="1500">
</div>
</div>
<div class="hero__item">
<div class="hero__media">
<img loading="lazy" src="/image2.jpg" width="2500" height="1500">
</div>
</div>
</div>
</div> The initialization for the carousel in question. 'use strict';
(function (Drupal, once, EmblaCarousel, EmblaCarouselAutoplay) {
const heroInit = (element) => {
const slides = element.querySelectorAll('.hero__item');
if (slides.length <= 1) {
return;
}
const options = {
loop: true,
delay: 6500,
duration: 40,
stopOnMouseEnter: true,
stopOnInteraction: false,
slides: slides,
};
const carousel = EmblaCarousel(element, options, [EmblaCarouselAutoplay()]);
}
Drupal.behaviors.heroInit = {
attach: (context, settings) => {
once('heroInit', '.hero', context).forEach(heroInit);
}
};
})(Drupal, once, EmblaCarousel, EmblaCarouselAutoplay); The simple workaround I've implemented works for the time being, but I would much prefer to use the API as intended. const autoplay = carousel.plugins().autoplay;
element.addEventListener('mouseenter', () => autoplay.stop());
element.addEventListener('mouseleave', () => autoplay.play()); I will gladly supply any additional information. Thanks much! If applicable, which variants of Embla Carousel are relevant to this question?
Additional informationNo response CodeSandbox exampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi @ItsFrankieD,
What do you mean by post-interaction? After dragging? Or clicking navigation buttons? |
Beta Was this translation helpful? Give feedback.
Hi @ItsFrankieD
Your problem is that you are writing the autoplay options together with the slider options
Please write the autoplay plugin options separately.
Replace