davidjerleke / embla-carousel

A lightweight carousel library with fluid motion and great swipe precision.
https://www.embla-carousel.com
MIT License
5.39k stars 166 forks source link

Expose the state for autoplay and events to listen to it #619

Closed davidjerleke closed 7 months ago

davidjerleke commented 8 months ago

👉 Credit goes to @kdzone. Discussed in https://github.com/davidjerleke/embla-carousel/discussions/308.

Feature request is related to

Is your feature request related to an issue

Originally posted by **kdzone** April 30, 2022 Playback can be stopped via stopOnMouseEnter and other internal events. How to change the styles of my `play` button?

Describe the solution you'd like

Originally posted by **kdzone** April 30, 2022 I suggest making a state for autoplay and an event to change it.

Specification:

emblaApi.on('autoplay:play', () => console.log('play'))
emblaApi.on('autoplay:stop', () => console.log('stop'))

emblaApi.plugins().autoplay.isPlaying() // --> boolean