0.0.8 • Published 5 years ago

tween-task v0.0.8

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

tween-task

npm Github file size

A lib to make easy tween task.

简易缓动函数库。

Installation

npm install tween-task

Usage

import Task from './tween-task';
// let Task = window.TweenTask; // window
// let Task = require('tween-task'); // commonjs

// run a task with default interval
// 使用内置的 setInterval 来启动任务
Task.run({
    from: { x: 1 },
    to: { x: 100 },
    onUpdate({ x }) {
        console.log('x has been updated:' + x);
    },
    done() {
        console.log('task has been done.')
    }
});

// or update when you like
// 或者在你喜欢的时机去更新

const task = new Task({
    from: { x: 1 },
    to: { x: 100 },
    onUpdate({ x }) {
        console.log('x is :' + x);
    },
    done() {
        console.log('task has been done.')
    }
});

(function update() {
    task.update();
    if (task.done) {
        return;
    }
    requestAnimationFrame(update);
})();

Support

IE6+

Api

ITaskOptions

interface ITaskOptions<T> {
    from: T;
    to: T;
    duration?: number;
    tween?: Function;
    onUpdate?: (cord: T) => void;
    done?: (cord: T) => void;
}
NameRequiredTypeDefaultDescription
fromtrueObjectproperties of from 起始的属性
totrueObjectproperties of to 目标属性
durationfalseNumber1000duration of the task. 任务持续时间
tweenfalseFunctiona function of linearcustom tween function 自定义的缓动函数
onUpdatefalseFunctionFunction invoked when task updated 任务每次更新的时候触发
donefalseFunctionFunction invoked when task finished 任务结束的时候触发

Methods

NameDescription
updatemake the task to computed 主动触发计算
disposedispose the task 释放资源、停止动画

Example:

const Task = new Task({...});
Task.update();

Enjoy it! :D

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago