Vas
Vas which is taken from the letters of Canvas is a independent component for simplifying wave-like chart building.
Features
-
Minimal ✔️
- Less than 2 kB with minified and gzipped.
-
Support any shapes container ✔️
- Define any shapes as all waves containers with the
plugin
option.
- Define any shapes as all waves containers with the
-
Portable ✔️
-
Only a few required parameters for fantastic canvas wave-like animation.
-
The target
<canvas>
element -
All members of flowing waves
-
-
-
No any third party dependence ✔️
- 100% independent.
Installation
# yarn yarn add vasjs # npm npm i vasjs --save
Wave options
Those options are used to control every single wave-like fluid.
Wave options | Required | Default | Description |
---|---|---|---|
height | ✔️ | N/A | Wave height |
color | / | #243d71 |
Wave body color |
progress | / | 0 | Wave level based on the bottom of canvas container |
offset | / | 0 | Wave offset is used for frozen waves which means only works with speed zero |
speed | / | RenderOptions.speed |
The flowing direction is from right to left when you set a positive value, otherwise, from left to right. Wave is static with zero speed. (Priority is higher than global speed option) |
NOTICE
- Wave body will be frozen when
Vas
gets a zero value from thespeed
option.
Global API
API | Required | Default | Description |
---|---|---|---|
el | ✔️ | N/A | A <canvas> element or selector string |
waves | ✔️ | N/A | Every fluid with its options |
width | / | 300 |
Canvas CSS width instead of logic width in the memory |
height | / | 300 |
Canvas CSS height instead of logic height in the memory |
devicePixelRatio | / | window.devicePixelRatio or if it does not exist, the value of option is 1. |
Hight resolution adaptation |
period | / | The value of a number rounded to the nearest quotient between global width and default lambda 60. | The period of waves |
speed | / | 0.3 |
The flowing direction is from right to left when you set a positive value, otherwise, from left to right. All waves are static with zero speed. |
plugin | / | N/A | The current CanvasRenderingContext2D will be passed into this function. |
NOTICE
-
RenderOptions.speed
(Global API) has a lower priority thanWaveOptions.speed
. -
The first item in the
RenderOptions.waves
list always be the top element in the scene. -
You should be careful about
plugin
options and color alpha value, because color alpha value could occur color composite.Canvas rendering context state will be saved before
plugin
calling, then restored afterplugin
calling.createRender
Instantiation
-
Basic creator
createRenderYou will see one wave with wave level 0.
-
Advanced creator
createRender -
With plugin functionalities, only support
border
temporarily.createRenderYou will see the shapes like demo page style.
Instance methods
It always returns an object including all render handlers when createRender
has been invoked.
// assign to a variable
API | Async / Sync | Description |
---|---|---|
on | sync | Activate all render process |
off | sync | Deactivate all render process |
Activate render process
on
:() => void
render.on
Deactivate render process
off
:(clear: boolean) => void
render.off // pause animation and clear canvas arearender.offtrue
Hight resolution adaptation
Hight resolution adaptation based on window.devicePixelRatio
has been supported by default (since v2.2.0
).
If you need to change default ratio:
createRender
Changelog
All notable changes to this project will be documented in CHANGELOG file.
License
MIT © Bowen Liu