Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot get Barba JS transition to work on page change

I'm trying to get Barba JS, alongside GSAP, implemented on my React website.

For reference, I have followed this video tutorial here, this tutorial of course, is not in React.

Here is my folder structure which showcases all of the relevant files for this transition effect:

theme
  public
    index.html
  src
    components
      Header
        Header.js
    pages
      Homepage
      Contact
    utils
      anim.js
      helpers.js
  App.js
  index.js

I have the following packages installed:

  • gsap - version 3.8.0
  • @barba/core - version 2.9.7

Current results

  • No console errors and no compilation errors.

  • When switching pages, there's no transition. It almost feels like barba isn't initiated.

Demo:

As the demo involves a few files, I have created a codesandbox here.

Edit:

Have updated my barba transition code and have added debug: true. Then, when hovering over my contact page button, the console shows the error: [@barba/core] Error: Fetch error at XMLHttpRequest.o.onerror?

import { pageTransition } from "./helpers";
import barba from '@barba/core';

export function delay(n) {
  n = n || 2000;
  return new Promise((done) => {
    setTimeout(() => {
      done();
    }, n);
  });
}

barba.init({
  debug: true,
  sync: true,
  transitions: [
    {
      async leave(data){
        const done = this.async();
        pageTransition();
        await delay(1000);
        done();
      }
    }
  ]
});
like image 854
Freddy Avatar asked Oct 11 '21 20:10

Freddy


People also ask

What is Barba JS?

What’s Barba.js? Barba.js is a JavaScript library that allows you to create fluid and smooth transitions between your websites pages. These transitions can be as simple as fading to the next page, and can be as complex as elements morphing into new ones as the user navigates through the side.

How to add animated page transitions in Barba JS?

When adding the Barba.js library to any website, you need to add two Divs. the first one is a wrapper that surrounds all of the content. The second is a container that the content in which you want to be animated during page transitions is contained in.

How to make page transitions in HTML?

How To Make Page Transitions in HTML – Barba.js and GSAP3 Tutorial 1. Create a loading screen. Firstly, we will create a loading screen .loader. This will be a container that will cover... 2. Include Barba.js. Include Barba.js at the bottom of both HTML files. I am also including GreenSock because ...

What is transition in Barba?

Transition A transition is a Javascript object that will make sure to hide the old container and display the new one. All the transitions need to extend the Barba.BaseTransiton object.


Video Answer


2 Answers

Dificult to say but you can set debug: true, inside the initialization of barba so it will spit out logs of whats happening ;)

barba.init({ debug: true, sync: false, //views das paginas views: [{.....

like image 197
Diego Gnoatto Avatar answered Oct 16 '22 19:10

Diego Gnoatto


I have since concluded that Barba JS is not compatible with React. Seems like the library needs updating to work with React Router.

More details here

like image 39
Freddy Avatar answered Oct 16 '22 21:10

Freddy