tween-one
## 如何使用
Last updated a year ago by jljsj33 .
Original npm · Tarball · package.json
$ npm install tween-one 
SYNC missed versions from official npm registry.

tween-one

如何使用

安装

$ npm install tween-one --save

使用

import TweenOne from 'tween-one';

const elem = {
  x: 0,
};

TweenOne(elem, { animation: { x: 100 } });

// timeline 示例

// 在播放完 x 轴动画后播放 y 轴动画
TweenOne(elem, { animation: [{ x: 100 }, { y: 100 }] });

/**
 *  x 轴动画正常播放,y 轴动画插入到时间轴 300ms处;
 * 如 x 的动画时间是 450, x 播放到 300 时,约 x = 90 时启动 y 动画.
 */
TweenOne(elem, { animation: [{ x: 100 }, { y: 100, appearTo: 300 }] });

实例方法使用

const t = TweenOne(elem, { animation: { x: 100 } });
t.paused = true; // 暂停动画
t.reverse = true; // 倒放
t.goto(200, true); // goto(moment: number, paused?: boolean); 跳到某时间点播放或停止;
t.kill(); // kill(index?: number); index 为 animation: [{ x: 1}, {y: 1}] 的序号,不传为全部杀掉;
TweenOne.kill(elem); // 杀死指定元素的全部动画,如果元素为空则杀死全局动画;

API

type time: 所有时间类的单位都为 ms

name type default description
animation object array null 动画属性参数, 详细参考以下
attr boolean false 如果 target 是 dom, 更改标签上的属性,需将此设为 true.
paused boolean false 暂停动画
reverse boolean false 倒放动画
repeat number 0 重复动画次数
repeatDelay time 0 重复动画开始播放时的延时
yoyo boolean false 重复动画时的第 n % 2 次是否反向动画
moment number 0 设置当前时间上的开始播放时间
onChange function null animation 里动画执行回调; (e: ICallBack) => void;
onChangeTimeline function null 时间轴动画的回调,增加了延时的回调 (e: ITimelineCallBack) => void;

animation

name type default description
[key: string] string number array null 以 number 为基础的所有变量,如 left, x, color, shadow.
type to from set to 播放类型,to 正常播放,from 反向播放, set 为 duration: 0.
startAt object null 设置开始动画的值.
duration time 450ms 动画时间
delay time 0 动画延时
repeat number 0 重复次数,-1 为无限重复播放
repeatDelay time 0 每次重复播放开始时延时
appearTo time 0 添加到时间轴某个位置
yoyo boolean false 重复时执行返回动画,如抽屉开关。
ease string easeInOutQuad 缓动参数. 参数名称参考 或为 SVG Path, svg 的大小,100 * 100 详细参考 ease path;
onStart function null 动画开始时回调, (e: ICallBack) => void;
onUpdate function null 动画更新时回调, (e: ICallBack) => void;
onComplete function null 动画结束时回调, (e: ICallBack) => void;
onRepeat function null 每次动画重复时回调, (e: ICallBack) => void;

ease path

以 M0,100 开始,100, 0 结束; 如下

const easePath =
  'M0,100 C7,89 14,81 21,78 C25,75 29,72 33,70 C37,66 39,62 42.5,57 C48,46.5 61.5,32.5 70,28 C77.5,23.5 81.5,20 86.5,16 C89,13 94,8 100,0';

ICallBack

type IMode = 'onUpdate' | 'onStart' | 'onComplete' | 'onRepeat';

name type description
mode IMode 回调的类型.
moment number 当前动画的时间.
ratio number 当前动画时间的面分比, 0 - 1
targets object[] 动画的元素,返回数组
vars object[] 当前动画的参数,返回数组, 与 targets 对应.
index number timeline 上的第几个动画.
repeat number 如果有重复,返回当前第几次重复

ITimelineCallBack

type ITimeLineMode = 'onTimelineUpdate' | 'onTimelineStart' | 'onTimelineComplete' | 'onTimelineRepeat' | 'onTimelineRepeatComplete' | 'onTimelineRepeatDelay';

name type description
mode ITimeLineMode 回调的类型.
moment number 当前动画的时间.
targets object[] 动画的元素,返回数组
vars object[] 当前动画的参数,返回数组, 与 targets 对应.
totalTime number timeline 动画的总时间.
repeat number 如果有重复,返回当前第几次重复

Current Tags

  • 1.2.7                                ...           latest (a year ago)

76 Versions

  • 1.2.7                                ...           a year ago
  • 1.2.6                                ...           2 years ago
  • 1.2.5                                ...           2 years ago
  • 1.2.4                                ...           2 years ago
  • 1.2.3                                ...           2 years ago
  • 1.2.2                                ...           2 years ago
  • 1.2.1                                ...           2 years ago
  • 1.1.8                                ...           3 years ago
  • 1.1.7                                ...           3 years ago
  • 1.1.6                                ...           3 years ago
  • 1.1.5                                ...           3 years ago
  • 1.1.4                                ...           3 years ago
  • 1.1.3                                ...           3 years ago
  • 1.1.2                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.63                                ...           3 years ago
  • 1.0.62                                ...           3 years ago
  • 1.0.61                                ...           3 years ago
  • 1.0.60                                ...           3 years ago
  • 1.0.58                                ...           3 years ago
  • 1.0.57                                ...           3 years ago
  • 1.0.55                                ...           3 years ago
  • 1.0.54                                ...           3 years ago
  • 1.0.53                                ...           3 years ago
  • 1.0.52                                ...           3 years ago
  • 1.0.51                                ...           3 years ago
  • 1.0.50                                ...           3 years ago
  • 1.0.49                                ...           3 years ago
  • 1.0.48                                ...           4 years ago
  • 1.0.47                                ...           4 years ago
  • 1.0.46                                ...           4 years ago
  • 1.0.45                                ...           4 years ago
  • 1.0.44                                ...           4 years ago
  • 1.0.43                                ...           4 years ago
  • 1.0.42                                ...           4 years ago
  • 1.0.41                                ...           4 years ago
  • 1.0.40                                ...           4 years ago
  • 1.0.39                                ...           4 years ago
  • 1.0.38                                ...           4 years ago
  • 1.0.37                                ...           4 years ago
  • 1.0.36                                ...           4 years ago
  • 1.0.35                                ...           4 years ago
  • 1.0.34                                ...           4 years ago
  • 1.0.33                                ...           4 years ago
  • 1.0.32                                ...           4 years ago
  • 1.0.31                                ...           4 years ago
  • 1.0.30                                ...           4 years ago
  • 1.0.29                                ...           4 years ago
  • 1.0.28                                ...           4 years ago
  • 1.0.27                                ...           4 years ago
  • 1.0.26                                ...           4 years ago
  • 1.0.23                                ...           4 years ago
  • 1.0.22                                ...           4 years ago
  • 1.0.21                                ...           4 years ago
  • 1.0.20                                ...           4 years ago
  • 1.0.19                                ...           4 years ago
  • 1.0.18                                ...           4 years ago
  • 1.0.17                                ...           4 years ago
  • 1.0.16                                ...           4 years ago
  • 1.0.15                                ...           4 years ago
  • 1.0.14                                ...           4 years ago
  • 1.0.13                                ...           4 years ago
  • 1.0.12                                ...           4 years ago
  • 1.0.11                                ...           4 years ago
  • 1.0.10                                ...           4 years ago
  • 1.0.9                                ...           4 years ago
  • 1.0.8                                ...           4 years ago
  • 1.0.7                                ...           4 years ago
  • 1.0.6                                ...           4 years ago
  • 1.0.5                                ...           4 years ago
  • 1.0.4                                ...           4 years ago
  • 1.0.3                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Total 2
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (6)
Dev Dependencies (11)
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE