How to use it with "Barba.js"
See original GitHub issueHello. How to use this plugin with barba.js? Is it correct way?
const scroll = new LocomotiveScroll({
el: document.querySelector('[data-scroll-container]'),
smooth: true,
getSpeed: true,
getDirection: true
});
// tell Barba to use the prefetch module
//barba.use(barbaPrefetch);
barba.hooks.afterEnter((data) => {
scroll.init();
});
barba.hooks.afterLeave((data) => {
scroll.destroy();
});
Issue Analytics
- State:
- Created 3 years ago
- Comments:20 (3 by maintainers)
Top Results From Across the Web
How it works - Barba.js
barba.js uses PJAX (aka push state ajax) to enhance the user's experience. This technique consist of preventing the normal link behavior, changing the ......
Read more >How To Make Page Transitions in HTML - Barba.js
Whilst creating page transitions may sound difficult, Barba.js makes the process incredibly easy. There are two types of page transitions: ... Now, let's...
Read more >Barba.js Tutorial for Beginners - Kontra Agency
Barba.js is a small and easy-to-use library that helps you create fluid and smooth transitions between your website's pages. It makes your ...
Read more >Barba.js Tutorial - How to add Transition Effect - Red Stapler
First let's start with downloading the latest release of Barba.js from github and import minified version of barba.js with a script tag to...
Read more >barbajs/barba: Create badass, fluid and smooth ... - GitHub
Barba.js is a small (7kb minified and compressed) and easy-to-use library that helps you create fluid and smooth transitions between your website's pages....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi everyone,
I just add a dedicated LocomotiveScroll section inside the advanced third party scripts documentation on the Barba website. Codepen will come later.
Happy reading! 😉
Hi everyone,
After a bunch of tests, LocomotiveScroll is well compatible with BarbaJS, but you can encounter issues when implementing it. In fact, you need to deal with:
The page template Having absolute or fixed elements on your page could end in a bad height calculation from LocomotiveScroll, in this case, always put the
data-scroll-container
attribute on the section of your site that scroll. (defaults is window.document)Barba page lifecycle As Barba makes your site running like a SPA, it won’t reload the whole page so the DOM can contain two Barba containers at the same time… and two Locomotive containers too! (check the Barba lifecycle documentation)
LocomotiveScroll settings If you don’t use the
smooth
option, the library works well as LocomotiveScroll is usingIntersectionObserver
feature… but whensmooth
option is enabled, the library use thedata-scroll-container
element in order to build the scroll, so you need to properly target it when next page is ready. (by instantiate LocomotiveScroll again).I will add a dedicated section in the advanced third party scripts documentation soon, and a codepen example!
😉 ✌️