Code Monkey home page Code Monkey logo

animore's Introduction

animore

Animore makes DOM state transitions easier It uses internally the css transitions to animate 2 different states of the same DOM node. It was inspired by riot-animore and works thanks to the flip technique by Paul Lewis

Build Status NPM version NPM downloads MIT License

Demos

Installation

Via npm

$ npm i animore -S

Script import

Via <script>

<script src="path/to/animore.js"></script>

Via ES2015 modules

import animore from 'animore'

Via commonjs

const animore = require('animore')

Usage

Simple transitions

You can pass a query or a DOM node to animore in the following way:

const animaQuery = animore('.my-div')[0] // animore returns always an array!
const animaNode = animore(myDiv)[0] // DOM nodes are also valid
const animaList = animore([myDiv, myUl]) // an arrays are also valid
const animaNodeList = animore(myUl.children) // NodeLists are valid as well

Remeber to use stash and apply to create your transitions

const anima = animore('.my-div')[0]
anima.stash() // store the previous DOM position
anima.el.style.marginTop = '300px'
anima.apply() // apply the transition

Options

The animore factory function accepts 2 arguments animore(el, options) with the options object you can specify how your animations should behave:

animore(myDiv, {
  duration: 300, // animation duration in ms
  easing: 'ease-in-out', // this should be a valid css easing function
  delay: 20, // animation delay
  onStart: function() { console.log('new animation started ')},
  onCancel: function() { console.log('animation canceled ')},
  onEnd: function() { console.log('animation ended ')}
})

API

Any animore call will return an object with the following properties

animore.stash

Store the current DOM node position and size

@returns self

animore.apply

Apply the transition comparing the current DOM node state with its previous state (it can be called only after a stash)

@returns self

animore.el

Reference to the DOM node queried

@returns HTMLElement

animore's People

Contributors

gianlucaguarini 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.