Quick Start

update by @r1ader in 2022/04/01

Introduction

r_animate.js helps us producing animation with functional programming

Most of methods in r_animate.js ,has the form like Things.do(something)

Take the fade-out animation as an example:

if element is the subject of the animation , then ths code should be

Let's focus on the last line of code,

There are three subjects element, r_animate , act.OUT.BLU

They correspond to Things,do 和 something

In the following, these three subjects will be explained separately

r(element) -> Thing

For r_animate.js , only the registered DOM Element Object, can make animation。

DOM Element is the Objects we get from

  • doument.getElementById in browser

  • this.$refs in vue

  • ...

But what is registered ?

Please imagine that on a movie set, there are many people: actors, directors, assistants, etc., but only the actors can perform.

So correspondingly, an ordinary Element object also needs to be registered as an Actor object to start the animation.

To register an Element , we us r to wrap it:

After register, you can call the .r_animate(...) to start the animation.

About r_animate ,continue to view 👇

r_animate -> do

r_animate is our most common method。

The above code will make element perform something animation

Notice:The details of something will be explained in detail in the third part. Currently, it can be directly understood as an animation such as zooming in and zooming out.

With functional programming, we can call r_animate for several times like this:

The above code will make element perform something_2 animation after something_1 is finished.

So it can go on and go on.

Take the fade-in and fade-out animation as an example, if we need such an animation:

The opacity of the ball first changes to 0 and then back to 1

Then the code is like this

check and run the code in stackblitz

About the parameter accepted by the r_animate , continue to view. 👇

act.OUT.OPACITY -> something

act.OUT.OPACITY is a parameter accepted by r_animate

In the act library, many animations are predefined for developers to call directly.

like

  • act.OUT.OPACITY

  • act.OUT.BLUR

  • act.IN.SCROLL_DOWN

  • act.EMPHASIZE.SHAKE_X

  • ...

Click to see more predefined animations

Of course, most cases require custom animations.

So let's take the real structure of act.OUT.OPACITY as an example to see how to customize the animation.

Yes, it's actually that simple.

This is the basic structure of an act.

act_key is the css property value that needs to be changed, such as opacity, width, top, etc.

act_value is a string composed of the initial value start and the end value end in the form of

[ start ~ end ]

Notice: start and end can only be numbers.

px, em, deg and other units need to be placed after brackets ]

Here are some examples of act :

Of course, if you don't need to consider the initial value, act_value also supports a more concise syntas:

It helps a lot when you are not certain about the start value of the animation.

Beside,

You may also need to configure the duration of the animation

and the interpolated form of motion tweening ease

About ease function ,check https://easings.net

ease also supports bezier mode

about cubic-bezier,check https://cubic-bezier.com/

For more configuration items, you can check in the Api Doc

Last updated