GithubHelp home page GithubHelp logo

anthrax3 / flipping Goto Github PK

View Code? Open in Web Editor NEW

This project forked from davidkpiano/flipping

0.0 1.0 0.0 196 KB

Flipping awesome animations.

License: MIT License

HTML 9.04% TypeScript 87.87% JavaScript 3.08%

flipping's Introduction

Flipping

A library (and collection of adapters) for implementing FLIP transitions.

For more information about the FLIP technique, view the flipping slides:

Examples

Installation

npm install flipping@latest --save

Or grab the files directly:

Quick Start

In your HTML, add the data-flip-key="..." attribute to shared elements (see HTML example below).

import Flipping from 'flipping';

const flipping = new Flipping();

// Before a layout change happens
flipping.read();

// Any effect that changes the layout
doSomething(); 

// After a layout change happens
// With an adapter, this will start the FLIP animation
flipping.flip();
<!-- first view -->
<section class="gallery">
  <div class="photo-1" data-flip-key="photo-1">
    <img src="/photo-1"/>
  </div>
  <div class="photo-2" data-flip-key="photo-2">
    <img src="/photo-2"/>
  </div>
  <div class="photo-3" data-flip-key="photo-3">
    <img src="/photo-3"/>
  </div>
</section>

<!-- second view -->
<section class="details">
  <div class="photo" data-flip-key="photo-1">
    <img src="/photo-1"/>
  </div>
  <p class="description">
    Lorem ipsum dolor sit amet...
  </p>
</section>

API

new Flipping(options?)

Creates a new Flipping instance. This is the thing that keeps track of all the changes made, and determines if any elements changed positions or size.

Parameters for options

For greater control and custom animations, you can pass in the following parameters (all optional):

  • selector?: (parent: Element) => Element[]; - Selects all "flippable" elements. Defaults to all elements that have a [data-flip-key] attribute.
  • activeSelector: (element) => Element[]; - Selects the currently active "flippable" elements. Defaults to selecting the visible flippable elements.
  • onFlip?: (state: IFlipStateMap) => void; - Event listener. Called with the entire state map of tracked flippable elements whenever .flip() is called.
  • onRead?: (state: IFlipStateMap) => void; - Event listener. Called with the entire state map of tracked flippable elements whenever .read() is called.
  • onEnter?: (state: IFlipStateMap) => void; - Event listener. Called with the state map of elements that enter (that is, not previously tracked).
  • onLeave?: (state: IFlipStateMap) => void; - Event listener. Called with the state map of elements that leave (that is, previously tracked but no longer active).
  • parent?: Element; - The root element to query all flippable elements. Defaults to the <body>.
  • plugins?: FlipPlugin[]; - An array of plugins that transform the state map before being emitted.

flipping.read(): void

Queries all the flippable selectors and reads their bounds (position and size). This must be called before layout cahnges are made.

Will call any onRead() event listeners with the entire state map.

flipping.flip(): void

Queries all the flippable selectors and reads their bounds (position and size), and then determines the deltas (changes in position and/or size)

Will call any onFlip() event listeners with the entire state map.

flipping.wrap(fn): void

  1. Calls flipping.read()
  2. Calls the wrapped fn()
  3. Returns the result of the wrapped fn()
  4. Calls flipping.flip()

It's a nice shorthand. Use it.

data-flip-key="..."

HTML data-attribute that tracks the same/shared elements and identifies them as the "same" element.

data-flip-no-scale

HTML data-attribute that prevents the Flipping adapters from trying to apply scale() to a transformed element.

flipping's People

Contributors

davidkpiano avatar mattahj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.