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.
Please note: the transition starts even before the new page is loaded. This way you can start your own transition even before the next page is loaded.
Extending this object your transition will inherit the following members:
Member | Description |
---|---|
start |
function that will be called automatically when your transition starts. (you can consider it the constructor of your transition) |
done |
function that needs to be called when your transition is finished.Do not forget to call this function! |
oldContainer |
HTMLElement of the old container. |
newContainerLoading |
Promise that will indicate the loading of the next container. |
newContainer |
HTMLElement of the new container. (with visibility: hidden; )Please note, it's undefined until newContainerLoading is resolved!
|
HideShow Example
By default barba.js uses a simple HideShow transition. In order to understand how it works, let's recreate it:
As you noticed we used a
Promise
; barba.js also comes with an handy Promise polyfill.
Next, we have to tell barba.js to use our new transition:
FadeTransition Example
Let's create now a more complex transition, a FadeTransition using jQuery's .animate()
Of course you can use any JS library, plain Javascript method, CSS transitions, or something else instead.