Barba: Changing the container class and main wrapper ID - help needed

Created on 28 Sep 2017  路  1Comment  路  Source: barbajs/barba

I've got this script up and running and works perfectly. However, I need a little help changing the ID of the main wrapper and the class of the container. I appreciate there's API documentation here, but how do you actually add the code into your build?

I'm currently using the transition example for the main barba.js site:

var FadeTransition = Barba.BaseTransition.extend({
  start: function() {
    /**
     * This function is automatically called as soon the Transition starts
     * this.newContainerLoading is a Promise for the loading of the new container
     * (Barba.js also comes with an handy Promise polyfill!)
     */

    // As soon the loading is finished and the old page is faded out, let's fade the new page
    Promise
      .all([this.newContainerLoading, this.fadeOut()])
      .then(this.fadeIn.bind(this));
  },

  fadeOut: function() {
    /**
     * this.oldContainer is the HTMLElement of the old Container
     */

    return $(this.oldContainer).animate({ opacity: 0 }).promise();
  },

  fadeIn: function() {
    /**
     * this.newContainer is the HTMLElement of the new Container
     * At this stage newContainer is on the DOM (inside our #barba-container and with visibility: hidden)
     * Please note, newContainer is available just after newContainerLoading is resolved!
     */

    var _this = this;
    var $el = $(this.newContainer);

    $(this.oldContainer).hide();

    $el.css({
      visibility : 'visible',
      opacity : 0
    });

    $el.animate({ opacity: 1 }, 400, function() {
      /**
       * Do not forget to call .done() as soon your transition is finished!
       * .done() will automatically remove from the DOM the old Container
       */

      _this.done();
    });
  }
});

/**
 * Next step, you have to tell Barba to use the new Transition
 */

Barba.Pjax.getTransition = function() {
  /**
   * Here you can use your own logic!
   * For example you can use different Transition based on the current page or link...
   */

  return FadeTransition;
};

Thanks in advance for the help!

Most helpful comment

Barba.Pjax.Dom.wrapperId = 'wrapper-name';
Barba.Pjax.Dom.containerClass = 'container-name';

Before calling Barba.Pjax.start()

>All comments

Barba.Pjax.Dom.wrapperId = 'wrapper-name';
Barba.Pjax.Dom.containerClass = 'container-name';

Before calling Barba.Pjax.start()

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Mexikaner9 picture Mexikaner9  路  3Comments

hosxes picture hosxes  路  3Comments

pburdylo picture pburdylo  路  3Comments

EmilyChews picture EmilyChews  路  3Comments

iamtompickering picture iamtompickering  路  3Comments