From 07dad7ee698663f6eda77cbea94622360f2afc74 Mon Sep 17 00:00:00 2001 From: youxia <243802688@qq.com> Date: Thu, 11 Jan 2024 15:03:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AF=B4=E6=98=8E=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 ++++++++-- src/hease.ts | 52 +++++++++++++++++++++++++++++++++------------------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index e31b2ce..b4561cd 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,17 @@ -## 一个超级精简的缓动库 +# hease +> 一个超级精简的缓动库 + +[![publish](https://github.com/hxg2050/hease/actions/workflows/publish.yml/badge.svg)](https://github.com/hxg2050/hease/actions/workflows/publish.yml) +[![npm-downloads](https://img.shields.io/npm/dm/hease.svg)](https://www.npmjs.com/package/hease) +[![npm-version](https://img.shields.io/npm/v/hease.svg)](https://www.npmjs.com/package/hease) 内置缓动函数速查表请参考: [https://easings.net/zh-cn](https://easings.net/zh-cn) +## 安装 ```sh npm install hease ``` - +## 例子 ```ts import { hease, EASE } from 'hease'; // 播放,并注册相关事件 diff --git a/src/hease.ts b/src/hease.ts index c0f8029..6e73dbd 100644 --- a/src/hease.ts +++ b/src/hease.ts @@ -11,37 +11,45 @@ export interface Hease { stop: () => this } +export type HEaseValue = number | number[]; -class _Hease extends EE { - constructor(public config: any) { - super(); - } +type en = never extends T ? K : never; - /** - * 起始状态 - */ - from() { - } +type a = en; +class _Hease extends EE { /** - * 目标状态 + * 起始属性 */ - to() { - - } - + from: T; /** - * 缓动函数 + * 结束属性 */ - ease() { - + to: T; + /** + * 动画时长 + */ + duration = 1000; + + constructor(public config: { + from: T, + to: T, + duration?: number, + ease?: (x: number) => number + }) { + super(); + this.from = config.from; + this.to = config.to; + if (Number.isFinite(config.duration)) { + this.duration = config.duration!; + } } /** - * 动画时长 + * 缓动函数 */ - duration() { + ease() { } @@ -88,6 +96,12 @@ class _Hease extends EE { } } +// const he = new _Hease({ +// 'from': [1], +// 'to': [1] +// }); +// const he2 = he.from([1, 2]);//.to(1); +// he2.to(1); /** * 简易刷新器 */