Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore CSS-driven springs #213

Open
appsforartists opened this issue Apr 27, 2017 · 2 comments
Open

Explore CSS-driven springs #213

appsforartists opened this issue Apr 27, 2017 · 2 comments

Comments

@appsforartists
Copy link
Member

appsforartists commented Apr 27, 2017

Here's a library that generates CSS keyframes using react-motion's interpolator: https://github.com/codepunkt/css-spring

@jverkoey has mentioned before that react-motion's algorithm isn't accurate. We ought to be able to build something similar with Rebound fairly easy.

Safari Tech Preview also seems to have an experimental animate: spring() CSS property. We should figure out what that's about and if we should evangelize/support it: https://lists.w3.org/Archives/Public/www-style/2016Jun/0181.html

@davidkpiano
Copy link

I had a very similar idea a long time ago - it's different from css-spring in that it doesn't generate a ton of keyframes (which is sort of the brute-force method) and instead focuses on three things:

  • A cubic-bezier timing function that's as close to a sine curve as possible
  • Calculating the logarithmic curve in which the harmonic motion decays
  • Calculating the local maxima/minima of the sine curve that is enveloped by the logarithmic curve

harmonic motion

Funny enough, this could be fully done in SCSS (but of course, it's not dynamic): http://codepen.io/davidkpiano/pen/e02140dd8e60651d8c917e93be998c5a

but it's a bit of a proof-of-concept. So instead of generating multiple keyframes:

  • generate a set number of keyframes that represent the maxima/minima (e.g., -100, 50, -25, 12, -6, 3, 0)
  • Set the timing function of each keyframe to the approximated sine cubic-bezier

@appsforartists
Copy link
Member Author

Nice! We've talked about that before too, but never bothered to do the math.

Great proof of concept! We don't have Tweens implemented yet, but when we do, it might be a good experiment to build a springSystem that emits a Tween with this pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants