项目作者: davesnx

项目描述 :
CSS-keyframes animations in Reason
高级语言: JavaScript
项目地址: git://github.com/davesnx/re-spring-css.git
创建时间: 2019-06-17T09:45:14Z
项目社区:https://github.com/davesnx/re-spring-css

开源协议:

下载


re-spring-css

re-spring-css makes it easy to create keyframes animations in Reason.

You define a spring: giving a tension and a friction (like chenglou/react-motion or react-spring.io) and it would create the keyframe!

  • It runs at 60 FPS.
  • Doesn’t block the DOM, like JavaScript-based animation libs.
  • Can’t be canceled or dynamically treated.

It’s an implementation in ReasonML of gerardabello/spring-animation-keyframes, all credits to him: @gerardabello.

How it works

This module depends on bs-css, ensure that you install both!

  1. module Styles = {
  2. open Css;
  3. open ReSpring;
  4. let fade =
  5. createPropertyKeyFrame(
  6. ~tension=120.,
  7. ~friction=40.,
  8. ~initialValue=0.,
  9. ~finalValue=1.,
  10. ~property=Css.opacity,
  11. );
  12. let jump =
  13. createTransformKeyFrame(
  14. ~tension=120.,
  15. ~friction=40.,
  16. ~initialValue=0.,
  17. ~finalValue=100.,
  18. ~transform=Css.translateX,
  19. );
  20. let crazyAnimation = Css.keyframes(merge(jump, fade));
  21. let root =
  22. style([
  23. width(px(50)),
  24. height(px(50)),
  25. backgroundColor(rgb(0, 0, 0)),
  26. animationName(crazyAnimation),
  27. animationDuration(2000),
  28. unsafe("animation-iteration-count", "infinite"),
  29. ]);
  30. };
  31. ReactDOMRe.renderToElementWithId(
  32. <div className=Styles.root> {ReasonReact.string("Hello!")} </div>,
  33. "index",
  34. );

Why

CSS animations runs at 60FPS (or more) even if the main thread is busy with parsing/executing JavaScript.

Contribute (Help!)

I have a list of issues to improve it here

  1. git clone https://github.com/davesnx/re-spring-css
  2. yarn install
  3. yarn start

Licence

MIT