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

flip-move

v1.0.2

Published

一种高效的动画技术,用于在Web应用程序中创建平滑的动画效果。使用 FLIP,动画的性能可以得到显著的提升,尤其是在移动设备和性能较差的机器上。

Downloads

66

Readme

flip-move

介绍

FLIP 是一种高效的动画技术,用于在 Web 应用程序中创建平滑的动画效果。FLIP 是“First, Last, Invert, Play”四个词的首字母缩写 ,它描述了实现动画的四个步骤流程。这种方法特别适用于那些涉及到元素尺寸(如宽度和高度)、位置(如页面上的坐标)或者其他可 以通过 CSS 变化的属性(如颜色)发生大的变化的动画效果。使用 FLIP,动画的性能可以得到显著的提升,尤其是在移动设备和性能较 差的机器上。

安装

$ npm i flip-move

$ pnpm i flip-move

$ yarn add flip-move

推荐使用的 node 版本和 npm 版本

{
  "node": ">=14.x.x",
  "npm": ">=6.x.x"
}

使用教程

import Flip from 'flip-move';

const div = document.querySelector('div');

/**
 * 初始化
 *
 * @param {Element} container 父容器元素
 * @param {number} duration 动画持续时间(默认值:500,单位:ms)
 */
const flip = new Flip(div, 500);

/**
 * 步骤1
 *
 * 记录初始状态(通常是页面元素的位置和尺寸)
 */
flip.first();

/**
 * 步骤2
 *
 * 根据自己的需求来定义元素怎么变化
 *
 * 这个是Demo(把容器最底部的元素插入到最顶部)
 */
const { children } = div;
const newnode = children[children.length - 1];
div.insertBefore(newnode, children[0]);

/**
 * 步骤3
 *
 * 使元素从反转的状态过渡到结束状态,会自动记录结束状态
 */
flip.play({
  // 当前变化的元素(可选)
  transform: (element) => {},
  // 单个动画结束回调(可选)
  callback: (element) => {},
  // 整体动画结束回调
  complete: () => {},
});

简单示例

import Flip from 'flip-move';

const list = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'purple'];

const div = document.createElement('div');

div.innerHTML = list.map((rgb) => `<div style="background-color:${rgb};">${rgb}</div>`).join('');

document.body.appendChild(div);

const flip = new Flip(div, 1000);

function play() {
  flip.first();

  const { children } = div;
  const newnode = children[children.length - 1];
  div.insertBefore(newnode, children[0]);

  flip.play({ complete: play });
}

play();