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

translate-flip

v0.4.3

Published

FLIP high performance CSS3 transformations & transitions

Downloads

14

Readme

FLIP high performance CSS3 transformations & transitions

Installation

Via npm

$ npm install translate-flip --save

Via yarn

$ yarn add translate-flip

Features

Extremely light weight

translate-flip is an extremely light weight transformation helper tool. It's only 10.8 kb after minimize.

High performance

Inspired by FLIP animation. Guarantee the least cost of making things move. If you are interested how FLIP works, please refer to FLIP Your Animations.

Interrupt during animation? Anytime!

translate-flip can interrupt the animation in any frame you want. It will start the next animation right after the frame you interrupted. All you need to do is simply call FLIP.magic.

Basic usage

Basic API is as below:

FLIP.magic(el, last, duration, easing, options)

It returns a Promise object.

Code below uses es6 feature:

import FLIP from 'translate-flip';

const { Easing } = FLIP;

FLIP.magic(element, {
  x: 10,
  y: 20,
  opacity: 0.4,
  scale: 0.5,
}, 1000, Easing.Ease).then(el => {
  // Animation end callback
  // parameter is the element which is just animated
}).catch(error => {
  // catch error
});

Advance usage

Interrupt then play

It is possible for you to interrupt an animation and then play another animation right after that frame. All you need to do is just call FLIP.magic whenever you want to interrupt.

FLIP.magic(element, {
  x: 100,
  y: 200,
}, 1000);

// 100ms later, change the moving destination of the element
// all you need to do is applying the magic again
// previous animation would be interrupted
// then smoothly play the lastest animation
window.setTimeout(() => {
  FLIP.magic(element, {
    x: 300,
    y: 50,
  }, 500);
}, 100);

Animation routine

Params including x, y, etc in translate-flip is relative to the element's initial position and status. If you want to transform the element according to the element's current position or status, you need to reload your element for translate-flip.

Not reloading:

// initial position of the element is x = 0, y = 0
FLIP
  .magic(element, {
    x: 100,
    y: 200,
  }, 1000)
  .then(el => {
    // now the position of element is x = 100, y = 200
    // but initial position is still x = 0, y = 0
    FLIP.magic(el, {
      x: 100,
      y: 200,
    }, 1000);
    // after second animation, position of the element will be x = 100, y = 200
  });

Reload after the first animation:

// initial position of the element is x = 0, y = 0
FLIP
  .magic(element, {
    x: 100,
    y: 200,
  }, 1000)
  .then(el => {
    // reload element for translate-flip
    FLIP.reload(el);
    // the initial position changed to x = 100, y = 200
    FLIP.magic(el, {
      x: 100,
      y: 200,
    }, 1000);
    // after second animation, position of the element will be x = 200, y = 400
  });

Easing functions

Built-in easing functions

translate-flip provides some built-in easing functions

  • Ease
  • EaseIn
  • EaseOut
  • EaseInOut
  • Linear
  • MDCubic: Conform to the standard bezier curve in Material Design

basic usage of easing functions:

const { Easing } = FLIP;

FLIP.magic(element, {
  x: 100,
  y: 200,
}, 1000, Easing.Linear);

Customize easing functions

Based on the cubic-bezier function supported by CSS, translate-flip allow you to customize your own easing function. For more details you can refer to Cubic Bezier.

const customizeEasing = Easing.Cubic(x1, y1, x2, y2);

Configure your animation

There are several configurable options as below

// took effect since v0.4.1
options: {
  /**
   * callback when animation is interrupted
   * param is the element animated
   */
  interrupt: (el) => { /* do stuff */ },

  /**
   * whether or not to use translate3d while animating the element, true by default
   * Please pay attention, under some specific circumstances, using translate3d may cause distortion.
   * For instance a param in transform is a decimal of many places, in this case the element may be distortion while using translate3d
   */
  use3d: true,
}

Something you need to know

Way for translate-flip to locate an element

Implementation of moving element from original place to target place is via left & right in css. Therefore elements with self-adaption, such as margin: auto, may not be animated correctly while using translate-flip.

If you want to animate element which contains any properties below, we suggest wrapping the element with a container and apply such css properties to it. And then FLIP with the element.

CSS properties FLIP not supporting

  • margin: auto
  • left: 50%
  • top: 30%

translate-flip does not support and also would not support elements with these css properties.

Supported animation params

Attention: rotate is partly supported. In animation routine, if interrupted, rotation can only perform angle less than 360°. If not rotation can perform angle larger than 360°. It is restricted by Interpolation of Matrices & Mathematical Description of Transform Functions.

  • x: translation along the X axis
  • y: translation along the Y axis
  • scale: scaling size, 1 for primitive size
  • opacity: opacity, [0, 1] float
  • rotate: angle of rotation [-360, 360]

These amazing people are maintaining this project:

No sponsors yet! Will you be the first?

These amazing people have contributed code to this project:

Unless stated otherwise all works are:

and licensed under: