GithubHelp home page GithubHelp logo

brunnolou / keyframe Goto Github PK

View Code? Open in Web Editor NEW
17.0 2.0 0.0 98 KB

A simple keyframe utility for custom animation

Home Page: https://brunnolou.github.io/keyframe/

License: MIT License

JavaScript 93.65% HTML 6.35%
keyframes animation timeline

keyframe's Introduction

Keyframe

A simple tiny keyframe utility for custom animation.

npm version 0 dependencies

Install

npm install --save keyframe

or

yarn add keyframe

Usage

Pass an object witch every key is the keyframe from 0 to 100.

Each keyframe is a function that will be called during the keyframe interval. Each passed function is cached and runs only once when the value is the same.

And will return a function to run through the keyframes progress.

const run = keyframe({
  50: (d) => update(d),
  100: (d) => update(d),
});

run(0);    // 0
run(0.25); // 0.5
run(0.5);  // 1
run(0.75); // 0.5
run(1);    // 1

Example

import keyframe from 'keyframe';

...

const moveTo = (x, y) => {
  div.style.transform = `translate(${x}px, ${y}px)`;
};

// From (0% -> 50%) move the div left 150px
// then from (50% -> 100%) move the div up 50px.
const onSliderUpdate = keyframe({
  // d is the duration between 0% -> 50%.
  50: d => moveTo(d * 150, 0),

  // d is the duration between 50% -> 100%.
  100: d => moveTo(150, d * -50),
});

// Return range between 0 and 1.
DOMslider.addEventListener('input', () => onSliderUpdate(slider.value / 100), true);

Check the examples/ folder to see full examples.

Or check out the DEMO page

Development

yarn install

yarn run dev

Test

yarn test

keyframe's People

Contributors

brunnolou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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