Published on

Motion.js

Authors

Motion.js

Motion.js

Info

Fallback text 1
Fallback text 2
Fallback text 3
Fallback text 4
Fallback text 5

What can be done

Fallback text 6
Fallback text 7
Fallback text 8

Debug

Fallback text 9

Examples

SVG loading spinner
Fallback text 10
Fallback text 11
Fallback text 12
SVG path drawing timeline
Fallback text 13
Fallback text 14
Fallback text 15

timeline is used to create complex sequences of animations across multiple elements. at is timer option, you can make a step in the animation start earlier like in the example. draw from what I understand is a specific option only applied to SVG tags.

Scroll-triggered animation
Fallback text 16
Fallback text 17
Fallback text 18

PS: inView is powerful!

Animating HTML text
Fallback text 19
Fallback text 20
Fallback text 21

animate can receive a function in the first parameter, it will return the progress of the animation we setup (number), with that we can do the changes we want.

Morph SVG path
Fallback text 22
Fallback text 23
Fallback text 24
Fallback text 25

flubber library is responsible for mashing the d attribute of the SVG path tag, they will create the adjustments based on the progress we pass into it. The animation with motion is the same as others, the only difference is the usage of flubber as a helper library to animate.

This library is used to smoothly interpolate between 2D shapes, it will guess what is the best method to transition between them. Only used for this

P5

Example with canvas!

Fallback text 26
Fallback text 27
Fallback text 28

P5 is a library used to handle with canvas. p5.setup is the function that will be executed first. startAnimation will be the function executed everytime we click on the canvas, it's responsability is to calculate based on X and Y clicked the intermediate values that will be drawn by p5.draw. x,y let variables are used inside p5.draw to draw to the position clicked. p5.draw is always drawing at 60 FPS. performance is a variable available from P5, its related to the frames of the canvas. @motionone is used to create the hue value used in the circle color.

Page progress bar
Fallback text 29
Fallback text 30
Fallback text 31
Element-based progress bar
Fallback text 32
Fallback text 33
Fallback text 34
Parallax and scroll-snapping

This animation is only related to the H2 tag, the scroll animation was done by scroll-snap, this is a new css property that provide a way to animate the scroll a bit.

Fallback text 35
Fallback text 36
Fallback text 37

header has a 100vh height, so it will take account the whole screen for the scroll animation.

Fade on enter/exit
Fallback text 38
Fallback text 39
Fallback text 40

PS: Maybe the offset is a custom one that take account of the start and end of the image in the scroll by using start and end

Video scrubbing

Video is playing by how much we scroll the page

Fallback text 41
Fallback text 42
Fallback text 43

target will make the scroll count only when the scroll has pass the start of the article tag.

3D camera

Rotate the Porsche using the progress of the scroll

Fallback text 44
Fallback text 45
Fallback text 46
Fallback text 47
Fallback text 48
Custom easing function
Fallback text 49
Fallback text 50
Fallback text 51

Comparison with other libraries

Compared with Anime.js and Greensock, Motion uses Web Animations API (WAAPI).

Benefits
  • Far smaller bundlesize
  • Hardware accelerated animations
  • Excellent value interpolation
Limitations

The main limitation of WAAPI is it can only animate CSS styles. So to animate HTML text, JavaScript values or SVG attributes like d we need to write custom animations:

Fallback text 52

Comparison table

Fallback text 53
Fallback text 54
Fallback text 55
Fallback text 56
Fallback text 57
Fallback text 58
Fallback text 59
Fallback text 60
Fallback text 61
Fallback text 62
Fallback text 63
Fallback text 64
Fallback text 65