npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xiaohe-transition

v1.1.0

Published

🏀 一个简单易用的贝塞尔曲线过渡动画工具

Downloads

45

Readme

github stars npm version npm downloads bundle JSDocs License

小何同学 / github@xiaohe0601 / gitee@xiaohe0601

🎉 特性

  • 🍜 支持非线性动画
  • 🍟 支持中途打断动画
  • 🌭 支持往复播放动画
  • 🧀 支持TypeScript
  • 🍳 支持免费商用
  • 🥗 更多特性等你发掘...

🚁 安装

PNPM

pnpm add xiaohe-transition

YARN

yarn add xiaohe-transition

NPM

npm install xiaohe-transition

🛹 使用

简单使用

import { Transition } from "xiaohe-transition";

const transition = new Transition((value) => {
  console.log("当前值发生变化", value);
});

transition.start({
  start: 0,
  target: 1000
});

// 如果是单页应用,请在合适的时机(如:页面销毁生命周期等)销毁动画,以避免内存泄露
transition.destroy();

重复播放

import { Transition, Repeater } from "xiaohe-transition";

const transition = new Transition({
  start: 0,
  target: 1000
}, (value) => {
  console.log("当前值发生变化", value);
});

// 调用start方法后,动画将会开始无限重复播放
const repeater = new Repeater(transition).start();

// 调用stop方法即可停止动画
repeater.stop();

// 如果是单页应用,请在合适的时机(如:页面销毁生命周期等)销毁动画,以避免内存泄露
repeater.destroy(); // repeater内部会自动调用 transition.destroy(),无需再手动调用

进阶用法

import { Transition, BezierCurvePreset } from "xiaohe-transition";

// 完整配置请参考下方 `类型定义` 中的说明
const transition = new Transition({
  // 持续时间
  duration: 10 * 1000,
  // 预设曲线
  preset: BezierCurvePreset.EASE_OUT,
  // 延迟开始时间
  delay: 500,
  // 帧率
  fps: 60,
  started(instance) {
    console.log("动画开始~");
  },
  paused(instance) {
    console.log("动画暂停~");
  },
  resumed(instance) {
    console.log("动画继续~");
  },
  stopped(instance) {
    console.log("动画停止~");
  },
  completed(instance) {
    console.log("动画完成~");
  }
}, (value, instance) => {
  console.log("当前值发生变化", value);
});

// 启动动画
transition.start({
  start: 0,
  target: 1000
});

setTimeout(() => {
  // 3秒后暂停动画
  transition.pause();

  setTimeout(() => {
    // 再2秒后继续动画
    transition.resume();

    setTimeout(() => {
      // 再3秒后停止动画
      transition.stop();
    }, 3 * 1000);
  }, 2 * 1000);
}, 3 * 1000);
import { Transition, Repeater, RepeatMode } from "xiaohe-transition";

const transition = new Transition({
  start: 0,
  target: 1000
}, (value) => {
  console.log("当前值发生变化", value);
});

// 完整配置请参考下方 `类型定义` 中的说明
const repeater = new Repeater(transition, {
  // 重复次数
  count: 10,
  // 重复模式
  mode: RepeatMode.ALTERNATE,
  started(instance, transition) {
    console.log("动画开始~");
  },
  paused(instance, transition) {
    console.log("动画暂停~");
  },
  resumed(instance, transition) {
    console.log("动画继续~");
  },
  stopped(instance, transition) {
    console.log("动画停止~");
  },
  // 注意!!!Transition的completed回调函数将会被Repeater占用,可使用repeated回调函数替代
  repeated(count, instance, transition) {
    console.log("动画重复~");
    console.log("已重复次数", count);
  },
  completed(instance, transition) {
    console.log("动画完成~");
  }
});

repeater.start();

// 现在应该使用Repeater中的相关方法来替代Transition控制动画
repeater.pause();
repeater.resume();
repeater.stop();

事件

配置项中的 回调函数 均支持 ononce 事件监听,下面以 started 事件举例

// 监听started事件
transition.on("started", (instance) => {
  console.log("动画开始~");
});

// 单次监听started事件,started事件触发一次后将自动取消监听
transition.once("started", (instance) => {
  console.log("动画开始~");
});

// 手动取消监听started事件
const unbind = transition.on("started", (instance) => {
  console.log("动画开始~");
});
// 调用on、once返回的unbind方法即可取消监听
unbind();

// 取消监听所有事件
transition.clearEvents();

类型定义

请查看 jsdocs.io

🛸 链接

  • bezier-easing cubic-bezier implementation for your JavaScript animation easings.

🐶 讨论交流

🏆 开源协议