Barba JS adding scripts to the DOM

715 views Asked by At
barba.init({ transitions: [ {
      name: 'general-transition-opacityfade',
      once({next}){
        animationEnter(next.container)
      },
      leave: ({current}) => animationLeave(current.container),
      enter({next}){
        animationEnter(next.container); }},

Re-run my JS script using Barba.JS Is there a way to add a script to the DOM and run on page enter?

1

There are 1 answers

1
tonsofcode On

You can specify what barba can do before enter after the transition that leads you to the new page.

For example, if you want to execute a script or a just a piece of code to the next transition you can use this.

barba.init({
  views: [{
    namespace: 'index',
    beforeLeave(data) {
      // do something before leaving the current `index` namespace
    }
  }, {
    namespace: 'contact',
    beforeEnter(data) {
      // do something before entering the `contact` namespace
    }
  }]
});

you can find the 'namespace' tag in every single HTML doc that you create and want to link with barbajs hope this works for you.