The problem is Plunker. Barba.js should work fine normally, but Plunker is using define() to do some AMD loading, and this is throwing off the Barba.js package.
Instead of assigning the exported Barba
to window
, the logic is using define()
because it is a global in Plunker.
If you want your example to work in global, you can make a slight modification to Barba.js just for the sake of a demo, OR you can try another tool such as Codepen.
To be honest, because of how Barba works, I'm not sure if any of the online tools will play well with it.
Nevertheless, if you want to make a small emendation just to get it to work, open barba.js in Plunker, you should see at the top:
1 (function webpackUniversalModuleDefinition(root, factory) {
2 if(typeof exports === 'object' && typeof module === 'object')
3 module.exports = factory();
4 else if(typeof define === 'function' && define.amd)
5 define("Barba", [], factory);
6 else if(typeof exports === 'object')
7 exports["Barba"] = factory();
8 else
9 root["Barba"] = factory();
10 })(this, function() {
Replace lines 2-9 with the following:
1 (function webpackUniversalModuleDefinition(root, factory) {
2 window["Barba"] = factory();
3 })(this, function() {
This should define Barba as a global so that your script.js
can use it.
Do NOT edit your original file on your local and try this in any other context. This is just for the sake of understanding, and the demo you are trying to run.
UPDATED
It should be noted that there is no way, given what Barba.js does, to know that it will work 100% in an online IDE or code sharing tool, such as plunker.
Per other questions in comments that you've asked, if you want to use the package, then, yes, it's best to have a local working version of your website. Your website should be able to work without using Barba at all. Then, once you're ready to add the nice transitions, add Barba, and get it working.
A xamp stack should work fine to run your website on your local.
Honestly, this is where you'll have to read Barba's docs thoroughly, and if you have troubles, search the package's Github issues to see if anyone else had something similar (https://github.com/luruke/barba.js/issues?page=1&q=is%3Aissue+is%3Aopen).