Barba: vanta.js (three.js) not working after page transition

Created on 23 Jul 2019  路  8Comments  路  Source: barbajs/barba

Hello,

sorry I'm a beginner and have a question that bugs me much...

so I want to use Vanta.js, which is a script for animated backgrounds using three.js
https://vantajs.com

I want this script to be executed in another page than the index, lets call it work-page

if I go from index to work-page, the vanta background is not showing up

but when I refresh the work-page, its visible

the init for vanta.js is

VANTA.WAVES({ el: "#vanta-output", color: 0xb38218, shininess: 40.00, waveHeight: 10.50, waveSpeed: 0.85 });

how come?

question v1

Most helpful comment

well i tried a bit with your information and i managed to make it work
thanks a lot!!

All 8 comments

Hi @kumaaa,

You should init your library in the associated page using Barba views: https://barba.js.org/docs/v2/user/core.html#view-object.

import barba from '@barba/core';

barba.init({
  views: [{
    namespace: 'work-page',
    beforeEnter() {
      VANTA.WAVES({
        el: "#vanta-output",
        color: 0xb38218,
        shininess: 40.00,
        waveHeight: 10.50,
        waveSpeed: 0.85
      });
    }
  }]
});

Don't know what kind of transition you are doing, but be sure that your #vanta-output element is present before entering the next page.

Note that you can use another hook to init your library

im using barba v1 and i tried to copy your code like this

`

Related issues

bobbyballard picture bobbyballard  路  3Comments

oguilleux picture oguilleux  路  3Comments

hosxes picture hosxes  路  3Comments

Mexikaner9 picture Mexikaner9  路  3Comments

kram08980 picture kram08980  路  3Comments