Transition.js
transition.js is a small (4kb minified and gzipped), flexible and dependency free library that helps you creating fluid and smooth transitions between your website's pages.
It helps reducing the delay between your pages, minimizing browser HTTP requests and enhancing your user's web experience.
How it works
Transition.js uses PJAX (aka push state ajax) to enhance the user's experience.
This technique consist in preventing the normal link behavior, changing manually the browser url, and injecting manually the new content in the page. In this way there will be no browser "hard refresh".
Here is a walkthrough of what happens when the user clicks a link:
- Check if the link is valid and eligible for PJAX, if yes, prevent the normal browser behavior.
- Change the URL using Push State API.
- Start fetching the new page via
XMLHttpRequest. - Create a new transition instance.
- As soon the new page is loaded, transition.js parses the new HTML (taking
.barba-container) and puts the new content on the DOM inside#barba-wrapper. - The transition instance will take care to hide the old container and show the new one.
- As soon the transition is finished, the old container is removed from the DOM.
Please note, on server side, your pages will need to be served normally.
Transition.js works as ehnancement for your website, everything should work normally without Javascript.
Why?
Using this technique will bring numerous benefits:
- Possibility to create nice transition between pages enhancing the user's experience.
- Reduce HTTP requests. (why reload the css/js at each page change?)
- Possibility to speed up the navigation using prefetch and cache.
Features
Installation
just include the script in your page:
<script src="transition.min.js" type="text/javascript"></script>
transition.js needs to know a little bit about your DOM structure. By default uses this markup structure in your pages:
<div id="barba-wrapper">
<div class="barba-container">
...Put here the content you wish to change between pages...
</div>
</div>
Please note, all the selector (#barba-wrapper, .barba-container) are easily editable, see the API section.
After you've included transition.js in your project it's time to initialize it
// Please note, the DOM should be ready
Barba.Pjax.start();
Other
For any other information, please visit my website and contact me

Log in or sign up for Devpost to join the conversation.