1.1.8 • Published 6 years ago

frameani v1.1.8

Weekly downloads
4
License
ISC
Repository
github
Last release
6 years ago

Frameani

Frameani is a highly free JavaScript animation library, it does care about how to create an animation by details, but will automatically calculate the motion value at different moments according to the animation-timing-function you provide, and how to render the animation is given to you to achieve.

For example, if you want to achieve a falling body motion of a sphere, after selecting the appropriate animation-timing-function, it will help you calculate the falling position for each frame

In addition, it provides you with a series of methods to better organize and manage animation queues, to help you create more complex animations, and even to combine multiple animations.

Installing

npm i frameani

Getting Started

import Frameani from "frameani";

const ele = document.querySelector("#target");

const frameani = new Frameani({
  value: [0, 500],
  duration: 1000,
  timingFunction: "easeOut",
  render: function(value) {
    ele.style.transform = `translateX(${value}px)`;
  },
  onPlay: () => console.log("begin!"),
  onEnd: () => console.log("end!")
});

frameani.play();

Parameter

namenecessarytypemeaningdefault
durationfalsenumberanimation runtime1000(ms)
valuetruearraystart and end point values/
rendertruefunctionrender callback function/
timingFunctionfalsestringanimation-timing-functionlinear
onPlayfalsefunctioncallback function of play event/
onStopfalsefunctioncallback function of stop event/
onEndfalsefunctioncallback function of end event/
onResetfalsefunctioncallback function of reset event/

Note that value is a special parameter that defines the start and end values of the animation, and frameani will calculate the motion value of the current time progress and return it as a parameter to the render callback function.

For example, to make an element moving 300px to the right within 3s at a constant speed, when it reaches 2 seconds, the value of the parameter in the render callback function is 200.

  • When the value is an array of two numbers, the first number is the starting value and the next one is the ending value.

    // Element moves 300px to the right
    const frameani = new Frameani({
      value: [0, 300],
      duration: 1000,
      render: function(value) {
        ele.style.transform = `translateX(${value}px)`;
      }
    });
  • When value is a two-dimensional array (each item is an array of two numbers), frameani will calculate the motion value of the current time progress for each array (the length of the two-dimensional array can be expanded infinitely).

    // Element moves 300px to the right and 500px to the down at the same time
    const frameani = new Frameani({
      value: [[0, 300], [0, 500]],
      duration: 1000,
      render: function(value1, value2) {
        ele.style.transform = `translate(${ value1 }px, ${ value2 }px)`;
      }
    })
  • When value is a object constructed by Frameani.path, frameani will get the point coordinates of the current time progress according to the given path to implement the custom path animation.

    const frameani = new Frameani({
      value: Frameani.path("M0 0L23 34L60 90Q32 46 23 12Q234 565 234 645Z"),
      duration: 1000,
      render: function(point) {
        ele.style.transform = `translate(${point.x}px, ${point.y}px)`;
      }
    });

API

frameani.play()

play animation

frameani.stop()

stop animation

frameani.end()

end animation

frameani.reset()

reset animation

frameani.to(option)

  • option consistent with the parameter format of the instantiated Frameani
  • returns itself

If you want to trigger a new animation at the end of the lastest animation, you can use the to method. It supports chained calls. Note that when the reset, stop or end method is called, all animations saved in the queue added via to will also be reset/paused/end

const ele1 = document.getElementById("target1");
const ele2 = document.getElementById("target2");
const frameani = new Frameani({
  value: [0, 500],
  duration: 1000,
  timingFunction: "easeOut",
  render: function(value) {
    ele1.style.transform = `translateX(${value}px)`;
  }
}).to({
  value: [0, 300],
  render: function(value) {
    ele2.style.transform = `translateY(${value}px)`;
  }
});

frameani.play();

frameani.with(option)

  • option consistent with the parameter format of the instantiated Frameani
  • returns itself

If you want to play another one while playing an animation, you can use the with method

const ele1 = document.getElementById("target1");
const ele2 = document.getElementById("target2");
const frameani = new Frameani({
  value: [0, 500],
  duration: 1000,
  timingFunction: "easeOut",
  render: function(value) {
    ele1.style.transform = `translateX(${value}px)`;
  }
}).width({
  value: [0, 300],
  render: function(value) {
    ele2.style.transform = `translateY(${value}px)`;
  }
});

Frameani.path(string)

  • string svg path string
  • returns object

It can help you to achieve more complex custom path animation. Note that in this case the argument to the render function will be modified: point is an object that saves the coordinates of the current point.

const frameani = new Frameani({
  value: Frameani.path("M0 0L23 34L60 90Q32 46 23 12Q234 565 234 645Z"),
  render: function(point) {
    ele.style.transform = `translate(${point.x}px,${point.y}px)`;
  },
  timingFunction: "easeOut",
  duration: 7000
});

frameani.play();
1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago