Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tween-one

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tween-one

## 如何使用

  • 1.2.7
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
44K
increased by14.32%
Maintainers
1
Weekly downloads
 
Created
Source

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

nametypedefaultdescription
animationobject arraynull动画属性参数, 详细参考以下
attrbooleanfalse如果 target 是 dom, 更改标签上的属性,需将此设为 true.
pausedbooleanfalse暂停动画
reversebooleanfalse倒放动画
repeatnumber0重复动画次数
repeatDelaytime0重复动画开始播放时的延时
yoyobooleanfalse重复动画时的第 n % 2 次是否反向动画
momentnumber0设置当前时间上的开始播放时间
onChangefunctionnullanimation 里动画执行回调; (e: ICallBack) => void;
onChangeTimelinefunctionnull时间轴动画的回调,增加了延时的回调 (e: ITimelineCallBack) => void;

animation

nametypedefaultdescription
[key: string]string number arraynull以 number 为基础的所有变量,如 left, x, color, shadow.
typeto from setto播放类型,to 正常播放,from 反向播放, set 为 duration: 0.
startAtobjectnull设置开始动画的值.
durationtime450ms动画时间
delaytime0动画延时
repeatnumber0重复次数,-1 为无限重复播放
repeatDelaytime0每次重复播放开始时延时
appearTotime0添加到时间轴某个位置
yoyobooleanfalse重复时执行返回动画,如抽屉开关。
easestringeaseInOutQuad缓动参数. 参数名称参考 或为 SVG Path, svg 的大小,100 * 100 详细参考 ease path;
onStartfunctionnull动画开始时回调, (e: ICallBack) => void;
onUpdatefunctionnull动画更新时回调, (e: ICallBack) => void;
onCompletefunctionnull动画结束时回调, (e: ICallBack) => void;
onRepeatfunctionnull每次动画重复时回调, (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';

nametypedescription
modeIMode回调的类型.
momentnumber当前动画的时间.
rationumber当前动画时间的面分比, 0 - 1
targetsobject[]动画的元素,返回数组
varsobject[]当前动画的参数,返回数组, 与 targets 对应.
indexnumbertimeline 上的第几个动画.
repeatnumber如果有重复,返回当前第几次重复
ITimelineCallBack

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

nametypedescription
modeITimeLineMode回调的类型.
momentnumber当前动画的时间.
targetsobject[]动画的元素,返回数组
varsobject[]当前动画的参数,返回数组, 与 targets 对应.
totalTimenumbertimeline 动画的总时间.
repeatnumber如果有重复,返回当前第几次重复

FAQs

Package last updated on 17 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc