Add 3D animated digital art to any webpage with just a few lines of code.
How it works: Vanta inserts an animated effect as a background into any HTML element.
Works with vanilla JS, React, Angular, Vue, etc.
Effects are rendered by three.js (using WebGL) or p5.js.
Effects can interact with mouse/touch inputs.
Effect parameters (e.g. color) can be easily modified to match your brand.
Total additional file size is ~120kb minified and gzipped (mostly three.js), which is smaller than comparable background images/videos.
Vanta includes many predefined effects to try out. More effects will be added soon!
In this article, I will introduce how to use vantajs with reactjs since I like reactjs lol.
Setup project
create a react project
install 2 libraries
create a component
Step1. Create a react project
This step is easy if you use codesandbox.io since you just need to click a react js project on dashboard.
If you prefer to use local dev env, you can use CRA(create-react-app), Vite etc.
Step2. Install 2 libraries
vantajs requires threejs or p5js. In this article, we will use threejs.
There is one cautionary point about threejs. You need to install version 0.121.0. There is no explanation about threejs version in the repo, but actually the latest one doesn't work well with vantajs.
After checking with codesandbox, vantajs works with by 0.124.0. From 0.125.0 there will be an issue. I haven't check the issue carefully so not sure that what the issue is exactly lol (I may check it later and open a PR)
To install a specific version of a js library, you need the following command.
In this case, the package-name is three and the version should be 0.121.0
# yarn
yarn add package-name@1.2.3
# npm
npm i package-name@1.2.3
Step3 Create a component
The code is simple. Importing libs for vantajs.
If you like to use a class component instead of a functional component, you will need to use componentDidMount() and componentWillUnmount(). You can check the code on the repo.