question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use it with "Barba.js"

See original GitHub issue

Hello. 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:closed
  • Created 3 years ago
  • Comments:20 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
xavierfoucriercommented, Apr 21, 2020

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! 😉

Related Barba repository issue: https://github.com/barbajs/barba/issues/511

6reactions
xavierfoucriercommented, Apr 21, 2020

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 using IntersectionObserver feature… but when smooth option is enabled, the library use the data-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!

😉 ✌️

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found