Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

vanta

tengbao28.9kMIT0.5.24

3D animated backgrounds for your website

animation, 3d, three, threejs, background, canvas, javascript, webgl

readme

Vanta JS

alt text

What is Vanta? / FAQs

  • 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!

Basic usage with script tags:

<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vanta/dist/vanta.waves.min.js"></script>
<script>
  VANTA.WAVES('#my-background')
</script>

View fiddle →

More options:

VANTA.WAVES({
  el: '#my-background', // element selector string or DOM object reference
  color: 0x000000,
  waveHeight: 20,
  shininess: 50,
  waveSpeed: 1.5,
  zoom: 0.75
})
  • el: The container element.

    • The Vanta canvas will be appended as a child of this element, and will assume the width and height of this element. (If you want a fullscreen canvas, make sure this container element is fullscreen.)
    • This container can have other children. The other children will appear as foreground content, in front of the Vanta canvas.
  • mouseControls: (defaults to true) Set to false to disable mouse controls. Only applies to certain effects.

  • touchControls: (defaults to true) Set to false to disable touch controls. Only applies to certain effects.

  • gyroControls: (defaults to false) Set to true to allow gyroscope to imitate mouse. Only applies to certain effects.

  • NOTE: Each effect has its own specific parameters. Explore them all at www.vantajs.com!

Updating options after init:

const effect = VANTA.WAVES({
  el: '#my-background',
  color: 0x000000
})

// Later, when you want to update an animation in progress with new options
effect.setOptions({
  color: 0xff88cc
})

// Later, if the container changes size and you want to force Vanta to redraw at the new canvas size
effect.resize()

Cleanup:

const effect = VANTA.WAVES('#my-background')
effect.destroy() // e.g. call this in React's componentWillUnmount

Usage with React Hooks:

npm i vanta, then import a specific effect as follows. Make sure three.js or p5.js has already been included via <script> tag.

import React, { useState, useEffect, useRef } from 'react'
import BIRDS from 'vanta/dist/vanta.birds.min'
// Make sure window.THREE is defined, e.g. by including three.min.js in the document head using a <script> tag

const MyComponent = (props) => {
  const [vantaEffect, setVantaEffect] = useState(null)
  const myRef = useRef(null)
  useEffect(() => {
    if (!vantaEffect) {
      setVantaEffect(BIRDS({
        el: myRef.current
      }))
    }
    return () => {
      if (vantaEffect) vantaEffect.destroy()
    }
  }, [vantaEffect])
  return <div ref={myRef}>
    Foreground content goes here
  </div>
}

View fiddle →

Usage with React Classes:

npm i vanta, then import a specific effect as follows. Make sure three.js or p5.js has already been included via <script> tag.

import React from 'react'
import BIRDS from 'vanta/dist/vanta.birds.min'
// Make sure window.THREE is defined, e.g. by including three.min.js in the document head using a <script> tag

class MyComponent extends React.Component {
  constructor() {
    super()
    this.vantaRef = React.createRef()
  }
  componentDidMount() {
    this.vantaEffect = BIRDS({
      el: this.vantaRef.current
    })
  }
  componentWillUnmount() {
    if (this.vantaEffect) this.vantaEffect.destroy()
  }
  render() {
    return <div ref={this.vantaRef}>
      Foreground content goes here
    </div>
  }
}

View fiddle →

Usage with Vue 2 (SFC):

<template>
  <div ref='vantaRef'>
    Foreground content here
  </div>
</template>

<script>
import BIRDS from 'vanta/dist/vanta.birds.min'
// Make sure window.THREE is defined, e.g. by including three.min.js in the document head using a <script> tag

export default {
  mounted() {
    this.vantaEffect = BIRDS({
      el: this.$refs.vantaRef
    })
  },
  beforeDestroy() {
    if (this.vantaEffect) {
      this.vantaEffect.destroy()
    }
  }
}
</script>

Using THREE or p5 from npm

For effects that use three.js, you can import three from npm, and pass it into the effect function.

import React from 'react'
import * as THREE from 'three'
import BIRDS from 'vanta/dist/vanta.birds.min'

...
  componentDidMount() {
    this.vantaEffect = BIRDS({
      el: this.vantaRef.current,
      THREE: THREE // use a custom THREE when initializing
    })
  }
...

For effects that use p5.js, you can import p5 from npm, and pass it into the effect function.

import React from 'react'
import p5 from 'p5'
import TRUNK from 'vanta/dist/vanta.trunk.min'

...
  componentDidMount() {
    this.vantaEffect = TRUNK({
      el: this.vantaRef.current,
      p5: p5 // use a custom p5 when initializing
    })
  }
...

Local dev:

Clone the repo, switch to the gallery branch, run npm install and npm run dev, and go to localhost:8080.

Credits

changelog

Vanta.js changelog

0.5.24

  • Update readme examples
  • Remove gallery images from main branch

0.5.23

  • Update waves, dots, globe to work with GeometryBuffer & latest three.js (@OmnesPotens, @DustinBrett)
  • Update birds to work with three.js r134
  • Fix animation speed bug
  • Fix custom three in halo
  • Bump three.js in examples to r134

0.5.22

  • Fix hash function in clouds
  • Update dependencies

0.5.21

  • Fix readme on npmjs.com
  • Fix fog on retina screens (@MaSchVam)

0.5.20

  • Add Vue.js example in readme
  • Add resize example in readme
  • Remove current reference on destroy

0.5.19

  • Fix globe color updating problem via setOptions
  • Update fiddle to use newest three.js

0.5.18

  • Upgrade three.js to r119
  • Upgrade effects to work with newest three.js

0.5.17

  • Fix custom THREE in birds
  • Call triggerMouseMove on setOptions

0.5.16

  • Add gyroControls option (@SrDonEmilio)
  • Add default params for triggerMouseMove

0.5.15

  • Add offset options for halo

0.5.14

  • Fix readme encoding
  • Add options for halo

0.5.13

  • Fix missing camera issue for some effects

0.5.12

  • Fix missing THREE for dots effect
  • Add initial halo effect

0.5.11

  • Fix resize issue for react

0.5.10

  • Update readme for npm
  • Added showLines option for dots effect

0.5.8

  • Initial publish on npm
  • Fixed wrong method name in readme

0.5.7

  • Removed gallery code from master branch, added to new gallery branch
  • Fixed an issue that prevented birds from being properly compiled in certain projects

0.5.6

  • Added ability to disable mouse/touch controls
  • Added ability to set custom scale

0.5.5

  • Fixed an issue with default height/width when the parent container (el param) has zero height
  • Fixed an issue with text nodes of el

0.5.4

  • Added ability to use a custom THREE build
  • Added example using create-react-app
  • Fixed an error with p5 effects expecting a threejs renderer

0.5.3

  • Fixed VANTA undefined error in waves effect
  • Added setOptions method to allow changing options after init
  • Added speed option for clouds

0.5.2

  • Added forceAnimate option
  • Added globe effect

0.5.1

  • Allow touchscreen controls for effects
  • Fixed an issue where Gatsby build fails due to window undefined

0.5.0

  • Updated module code to allow static import
  • Updated readme React example to use refs
  • Fixed issue where sibling elements are overlaid on top of the animation element and mousemove fails to trigger, now using window mousemove event
  • Added warning if THREE is missing on window
  • Added this changelog

0.4.0

  • Added mobile support for birds effect (alternative to GPGPU)
  • Added bird size option for birds effect

0.3.0

  • Removed backgroundColor "transparent" option, use backgroundAlpha instead

0.2.0

  • Added p5 effects: trunk, topology
  • Updated dots with a spherical effect

0.1.0

  • First release