@vanillagorilla see details in this post for the JS part (the HTML part is is pretty straightforward if you add the wrapping classes).
It works well but now the headache I have is with plugins that add their own CSS to the head (hello Elementor!) or worse, plugins (ie. Revolution Slider) that add blocks of javascript inside <script>
tags - it doesn’t get executed when loaded via AJAX…
I like the way Barba.js works but I’m beginning to wonder if the complexity it adds to a WordPress setup is worth it!