davidjerleke / embla-carousel

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

Inconsistent animation speed depending on monitor refresh rate #387

Closed macjuul closed 1 year ago

macjuul commented 1 year ago

Bug is related to

Embla Carousel version

Describe the bug

CodeSandbox

Steps to reproduce

  1. View a carousel normally (either with 60Hz or higher)
  2. Limit your browser framerate to 30Hz or lower (You can do this in Firefox by setting layout.frame_rate to 30 in about:config)
  3. View the same carousel again, you will notice slide animations being twice as slow

Expected behavior

Additional context

Thank you for your great library!

davidjerleke commented 1 year ago

Hi @macjuul,

Yep, I actually already have this on my to do so thank you for creating this issue 👍🏻. I’ll let you know when I have something.

Best, David

robksawyer commented 1 year ago

Anyway we could add the ability to adjust the ease type? Using different easings with the autoplay plugin would be a win!

Update: I realized all I needed to do is adjust the timing on the container via css. I'm using tailwind and adding the following class to the inner container div made things much smoother.

.ease-out-quad {
    transition-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
macjuul commented 1 year ago

Hey @davidjerleke, have you had any time to look into this yet? or perhaps an estimate on when this could be tackled?

Thanks!

davidjerleke commented 1 year ago

Hi @macjuul,

Thanks for the follow up. I can’t give proper time estimates because I’m the sole dev on this project with a huge to do list, and I’m maintaining this on my spare time which means a little bit here and there.

But what I can say is that I have it planned for the 7.2.1 release:

Best, David

macjuul commented 1 year ago

Great to hear @davidjerleke! Thanks for the heads up, looking forward to a fix. Take your time, no need to hurry 🙂

davidjerleke commented 1 year ago

@macjuul, just wanted to let you know that I will start working on this issue the next time I work on this project. Can’t give an ETA though but I will start looking into it.

davidjerleke commented 1 year ago

Hi @macjuul,

If you want to help out and speed up the process, you could test this CodeSandbox on:

The total runtime for the animation on each device should be something around 1500 milliseconds (give and take 30 milliseconds), no matter the refresh rate.

If that's the case, I have a good starting point and will continue implementing this feature into the Embla Carousel core. Also note that the runtime won't be exactly 1500 and may slightly vary from one try to another (about 30 milliseconds give and take).

Thanks in advance. David

macjuul commented 1 year ago

Hi @macjuul,

If you want to help out and speed up the process, you could test this CodeSandbox on:

  • On a 60 Hz device.
  • On a 120 Hz device.

The total runtime for the animation on each device should be something around 1500 milliseconds (give and take 30 milliseconds), no matter the refresh rate.

If that's the case, I have a good starting point and will continue implementing this feature into the Embla Carousel core. Also note that the runtime won't be exactly 1500 and may slightly vary from one try to another (about 30 milliseconds give and take).

Thanks in advance. David

This is indeed working perfectly on 144hz, 60hz, and 30hz. Good job!

davidjerleke commented 1 year ago

@macjuul, thanks for taking time and testing it out 👍. I'll let you know when I have a working frame rate agnostic Embla draft.

davidjerleke commented 1 year ago

Hi @macjuul and anyone tracking this issue. I’m done implementing this feature and it will be released with v8.0.0-rc01 pretty soon. I just have to update some examples on the documentation website. Stay tuned.

Best, David

davidjerleke commented 1 year ago

To be released with v8.0.0-rc01.

davidjerleke commented 1 year ago

@macjuul this feature has been released with v8.0.0-rc01.