项目作者: react-component

项目描述 :
Animate One React Element
高级语言: JavaScript
项目地址: git://github.com/react-component/tween-one.git
创建时间: 2015-12-21T12:28:15Z
项目社区:https://github.com/react-component/tween-one

开源协议:MIT License

下载


rc-tween-one


React TweenOne Component

NPM version
build status
Codecov
node version
npm download

Browser Support

IE Chrome Firefox Opera Safari
IE 10+ ✔ Chrome 31.0+ ✔ Firefox 31.0+ ✔ Opera 30.0+ ✔ Safari 7.0+ ✔

Development

  1. npm install
  2. npm start

Example

http://localhost:8100/examples/

2.x: http://react-component.github.io/tween-one/

3.x: https://tween-one.vercel.app/

install

rc-tween-one

Usage

```js | pure
var TweenOne = require(‘rc-tween-one’);
var React = require(‘react’);
React.render(
demo
, container);

  1. ### Plugin
  2. ```js | pure
  3. var TweenOne = require('rc-tween-one');
  4. var React = require('react');
  5. var SvgDrawPlugin = require('rc-tween-one/lib/plugin/SvgDrawPlugin');
  6. TweenOne.plugins.push(SvgDrawPlugin);
  7. React.render(<svg width="600" height="600">
  8. <TweenOne
  9. animation={{ SVGDraw:'50%'}}
  10. d="M0,0L100,0"
  11. style={{ fill: 'none', strokeWidth: 20, stroke: '#00000' }}
  12. component="path"
  13. ></TweenOne>
  14. </svg>, container);

TweenOneGroup

```js | pure
var TweenOne = require(‘rc-tween-one’);
var React = require(‘react’);
var TweenOneGroup = TweenOne.TweenOneGroup;
React.render(

demo

demo

, container);

  1. ## API
  2. <a href='https://motion.ant.design/api/tween-one' target='_blank'>中文文档</a>
  3. ### props
  4. | name | type | default | description |
  5. |------------|----------------|---------|----------------|
  6. | animation | object / array | null | animate configure parameters |
  7. | paused | boolean | false | animate timeline pause |
  8. | reverse | boolean | false | animate timeline revers |
  9. | delay | number | 0 | animate timeline delay |
  10. | repeat | number | 0 | `animation` all data repeat, To repeat indefinitely, use -1 |
  11. | repeatDelay | number | 0 | animate timeline repeat delay |
  12. | yoyo | boolean | false | `animation` all data alternating backward and forward on each repeat. |
  13. | onChange | func | null | when the animation change called, callback({ moment, targets, index, mode, ratio, vars, index, repeat }) |
  14. | onChangeTimeline | func | null | when the animation change called, callback({ mode, targets, vars, moment, totalTime, repeat }) |
  15. | moment | number | null | set the current frame |
  16. | regionStartTime | number | 0 | Set the start time of the animation region |
  17. | regionEndTime | number | null | Set the end time of the animation region |
  18. | attr | boolean | false | attribute animation is `true`, when morph SVG must be `true`. |
  19. | resetStyle | boolean | false | update animation data, reset init style |
  20. | component | string / React.Element | `div` | component tag |
  21. | componentProps | object | null | component is React.Element, component tag props, not add `style` |
  22. ### animation = { }
  23. > Basic animation param. please view [animation terms](https://motion.ant.design/language/animate-term)
  24. | name | type | default | description |
  25. |------------|----------------|---------|----------------|
  26. | [key: string] | `string` `number` `array` | null | All variables based on number, such as left, x, color, shadow |
  27. | type | string | `to` | play type: `to` `from` `set`|
  28. | duration | number | 450 | animate duration |
  29. | delay | number | 0 | animate delay |
  30. | repeat | number | 0 | animate repeat, To repeat indefinitely, use -1 |
  31. | repeatDelay| number | 0 | repeat start delay |
  32. | appearTo | number | null | Add to the specified time |
  33. | yoyo | boolean | false | `true`: alternating backward and forward on each repeat. |
  34. | ease | string | `easeInOutQuad` | animate ease [refer](http://easings.net/en) or svg path `M0,100 C30,60 0,20 50,50 C70,70 60,0 100,0` |
  35. | bezier | object | null | bezier curve animate |
  36. | onStart | func | null | A function that should be called when the tween begins, callback(e), e: { index, target } |
  37. | onUpdate | func | null | A function that should be called every time the animate updates, callback(e), e: { index, targets, ratio } |
  38. | onComplete | func | null | A function that should be called when the animate has completed, callback(e), e: { index, targets } |
  39. | onRepeat | func | null | A function that should be called each time the animate repeats, callback(e), e: { index, targets } |
  40. > Cannot be used at the same time `reverse` and `repeat: -1`.
  41. ### animation =[ ] is timeline
  42. ```js | pure
  43. <TweenOne animation={[{ x: 100 }, { y: 100 }]} ></TweenOne>

Plugins

SvgDrawPlugin

```js | pure
import { Plugins } from ‘rc-tween-one’;
import SvgDrawPlugin from ‘rc-tween-one/es/plugin/SvgDrawPlugin’;
Plugins.push(SvgDrawPlugin);

  1. SVGDraw = string or number;
  2. { SVGDraw: 30 } or { SVGDraw: 'start end' } start and end values can be `%`;
  3. ### SvgMorphPlugin
  4. ```js | pure
  5. import { Plugins } from 'rc-tween-one';
  6. import SvgMorphPlugin from 'rc-tween-one/es/plugin/SvgMorphPlugin';
  7. Plugins.push(SvgMorphPlugin);
  8. <TweenOne animation={{ SVGMorph: { path: '300,10 500,200 120,230 450,220 0,20' }}} ></TweenOne>

SvgMorphPlugin API

name type default description
path string null svg path, ref: M0,0L100,0;
attr string null Svg tag attributes, example: polygon is points, path is d.
maxSegmentLength number 0.5 The lower the value, the smoother the generated animation will be, but at the expense of performance;

PathPlugin

```js | pure
import { Plugins } from ‘rc-tween-one’;
import PathMotionPlugin from ‘rc-tween-one/es/plugin/PathMotionPlugin’;
Plugins.push(PathMotionPlugin);


```

PathMotion API

name type default description
path string / {x,y}[] null svg path, ref: M0,0L100,0;
pathVars IPathVars null Only valid if path is array [{x, y}, {x, y}]
center number \ string[] ['50%','50%'] center point, ref: [50px, 50px];
x boolean true x follow the path.
y boolean true y follow the path.
rotate boolean true rotate follow the path.
IPathVars
name type default description
type thru \ soft \ cubic thru path type. thru same as the path; soft with the curve of attraction facing them, but not through the point; cubic allows you to define standard Cubic Bezier, example: [start, control, control, end].
curviness 0-2 1 This determines how “curvy” the resulting path is. 0 is lines, 1 is curved path, 2 would make it much more curvy. It can be 1.5.
relative boolean false Increase relative to current value. example: if the target’s x starts at 100 and the path is [{x:5}, {x:10}, {x:-2}] , it would first move to 105, then 115, and finally end at 113.

ChildrenPlugin

Children = { value:, floatLength, formatMoney };

name type default description
value number null children number to value.
floatLength number null float precision length
formatMoney true \ { thousand, decimal } null format number to money.

formatMoney = { thousand, decimal }

name type default description
thousand string , no explanation.
decimal string . no explanation.

TweenOneGroup

name type default description
appear boolean true whether support appear anim
enter object / array / func { x: 30, opacity: 0, type: 'from' } enter anim twee-one data. when array is tween-one timeline, func refer to queue-anim
leave object / array / func { x: 30, opacity: 0 } leave anim twee-one data. when array is tween-one timeline, func refer to queue-anim
onEnd func - one animation end callback
animatingClassName array ['tween-one-entering', 'tween-one-leaving'] className to every element of animating
resetStyle boolean true TweenOne resetStyle, reset the initial style when changing animation.
exclusive boolean false Whether to allow a new animate to execute immediately when switching. enter => leave: execute immediately leave
component React.Element/String div component tag
componentProps object - component tag props