Barba: Enter transition not showing

Created on 27 Jul 2020  路  5Comments  路  Source: barbajs/barba

The problem

Whenever trying to transition to another page, the enter transition isn't shown (latest barba.js version) - I'm currently using the sample code from #498, which seems to run fine in their codepen.

Description

Expected behaviour

The page should fade out, the next should fade in

Actual behaviour

.. instead, this happens:

Peek 2020-07-27 12-33

Code To Reproduce Issue [ Good To Have ]

function leaveAnimation(e) {
    return new Promise(async resolve => {
        var target = e.querySelectorAll('main');

        anime( {
            targets: target,
            opacity: [1, 0],
            duration: 500,
            easing: 'linear',
            complete: () => {
                resolve();
            },
        });
    });
}

function enterAnimation(e) {
    return new Promise(async resolve => {
        var target = e.querySelectorAll('main');

        anime( {
            targets: target,
            opacity: [0, 1],
            duration: 500,
            easing: 'linear',
            complete: () => {
                resolve();
            },
        });
    });
}

// .. and then:

barba.init({
    debug: true,
    transitions: [ {
        name: 'broken-transition',
        sync: false,
        once: ({ next }) => enterAnimation(next.container),
        leave: ({ current }) => leaveAnimation(current.container),
        enter: ({ next }) => enterAnimation(next.container)
    }],
});

Steps to reproduce issue [ Good To Have ]

Install anime.js and paste above code.


Environment

  • Barba version that exhibits the issue:
  • Build used:

    • [ ] module (esm/)

    • [x] browser (dist/)

    • [ ] main (lib/)

  • Browser OS/version used:
question

All 5 comments

Hi @S1SYPHOS,

This issue is more related to how your code is running than Barba v2 implementation...

For those kind of questions/help, please use the Slack workspace in order to ask the whole community for support. Join using the invite link here: https://barba.js.org/docs/getstarted/useful-links/#Developer

Anyway, here are some fix you should do in your code:

Hope this help :wink:
I am closing the issue.

Right, the async was a leftover from some example code and not responsible for the behavior by itself, but I appreciate your kind help.

In addition, latest anime.js version support Promise, so you don't need to encapsulate your code inside a Promise, just use anime(... inside your animation methods.

Well, after playing a little, this works the way I intended it:

barba.init({
    debug: true,
    transitions: [{
        leave: (data) => {
            return new Promise(resolve => {
                anime({
                    targets: data.current.container,
                    opacity: 0,
                    complete: () => {
                        resolve();
                    }
                });
            });
        },
        enter: (data) => {
            anime({
                targets: data.next.container,
                opacity: [0, 1],
            });
        },
    }]
});

.. not returning a Promise on the second one.

@S1SYPHOS exactly what I was meaning/thinking in my previous comment, you can write hooks in many ways, see https://barba.js.org/docs/advanced/hooks/#Base-hooks.

I updated my comment as I wrote it late at night on my phone :smile:

Was this page helpful?
0 / 5 - 0 ratings