davidjerleke / embla-carousel

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

Replace option `align:number` with a callback #594

Closed davidjerleke closed 8 months ago

davidjerleke commented 8 months ago

Feature request is related to

Describe the solution you'd like (discussed in https://github.com/davidjerleke/embla-carousel/discussions/579)

Originally posted by **davidjerleke** September 25, 2023 @tobimori we could **replace the number option** with a **callback** function like so:
```ts const options = { align: (viewSize, snapSize, index) => { // create your own alignment return yourCustomAlignment } } ``` The benefit of this would be that you would have direct access to the size of the container (viewSize) and the current slide/slideGroup (itemSize) which is convenient because you don't have to read element dimensions yourself. Note that the **function** would **run** for **each and every scroll snap**. This would be even more flexible than the previous implementation and wouldn't affect bundle size.