项目作者: nicopowa

项目描述 :
lightweight animation engine
高级语言: JavaScript
项目地址: git://github.com/nicopowa/effect.git
创建时间: 2019-06-29T08:55:15Z
项目社区:https://github.com/nicopowa/effect

开源协议:

下载


Effect

lightweight animation engine

https://nicopr.fr/effect

Features

  • 2k minified JS
  • 2.3k GZIP (ノಠ益ಠ)ノ彡┻━━┻
  • no CSS
  • easing, delay, override
  • async/await animations for easy timeline

Why ?

Playing with vanilla JS ice cream since it’s hot in Paris these days.

A web page with a menu, a picture and some text doesn’t require 2Mb JS code.

Demo

https://nicopowa.github.io/effect/index.html

same code with gsap wrapper : https://nicopowa.github.io/effect/gsap.html

How it works

  • play all effects from a single frame loop
  • parse css properties
  • on each frame: loop effects, properties, and numeric values
  • skip frames to preserve time accuracy
  • keep track of effects to override or stop (data-eff HTML attribute)

Animated CSS properties must be initialized on HTML elements before playing effects.

How to make it work

  1. // simple effect
  2. myElement.style.width = "50px"; // important ! set initial value
  3. let myEffect = new Effect(myElement, 60, {width: 100}); // or "100px"
  4. myEffect.play();
  5. // async effect
  6. myElement.style.left= "10px"; // important ! set initial value
  7. let go = new Effect(myElement, 60, {left: 100}); // or "100px"
  8. let back = new Effect(myElement, 60, {left: 10}); // or "10px"
  9. await go.play();
  10. await back.play();

Easing

3 built-in easing functions : quartIn, quartOut, quartInOut

To add custom easing :

  1. Effect.bounceOut = function(t, b, c, d) {
  2. if((t /= d) < (1 / 2.75)) return c * (7.5625 * t * t) + b;
  3. else if(t < (2 / 2.75)) return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
  4. else if(t < (2.5 / 2.75)) return c * (7.5625 * (t -= (2.25 / 2.75))*t + .9375) + b;
  5. else return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
  6. }

Bugs

  • iOS Safari animate transform flicker fix :

    1. .animated {
    2. will-change: transform;
    3. }