Jump to content
Search Community

Can gsap and locomotive scroll work together

Ayanoo test
Moderator Tag

Recommended Posts

I am trying the exact same thing i saw in tutorials but don't now why I am still getting the locoScroll.on isn't a function error

 

here is my code :

 

 

import gsap from "gsap";
import ScrollTrigger from "gsap/ScrollTrigger";
import LocomotiveScroll from "locomotive-scroll";
 
const scrollLoco = () => {
    gsap.registerPlugin(ScrollTrigger)
 
    const scrollEl = document.querySelector('.main');
 
    let locoScroll = new LocomotiveScroll({
        el: scrollEl,
        smooth: true,
        multiplier: 1.5,
    });
 
    locoScroll.on('scroll', ScrollTrigger.update);
 
    ScrollTrigger.scrollerProxy(scrollEl, {
        scrollTop(value) {
            if (locoScroll) {
                return arguments.length
                    ? locoScroll.scrollTo(value, 0, 0)
                    : locoScroll.scroll.instance.scroll.y;
            }
            return null;
        },
        scrollLeft(value) {
            if (locoScroll) {
                return arguments.length
                    ? locoScroll.scrollTo(value, 0, 0)
                    : locoScroll.scroll.instance.scroll.x;
            }
            return null;
        },
        getBoundingClientRect() {
            return {
                top: 0,
                left: 0,
                width: window.innerWidth,
                height: window.innerHeight,
            };
        },
    });
 
    const lsUpdate = () => {
        if (locoScroll) {
            locoScroll.update();
        }
    };
 
    ScrollTrigger.addEventListener('refresh', lsUpdate);
    ScrollTrigger.refresh();
}
 
export default scrollLoco
Link to comment
Share on other sites

Hm, it's super difficult to troubleshoot without a minimal demo - this sounds like a LocomotiveScroll issue, not a GSAP one. I wonder if you've got a mismatched version of it, like maybe LocomotiveScroll changed their API and the main LocomotiveScroll instance doesn't have that property anymore. I'm really not familiar with LocomotiveScroll, sorry. We really try to keep these forums focused on GSAP-related questions (please read the forum guidelines)

 

If you still need help, please make sure you provide a very simple CodePen or Stackblitz that demonstrates the issue.  

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen

 

Using a framework/library like React, Vue, Next, etc.? 

CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: 

 

Link to comment
Share on other sites

Hi,

 

On top of needing a minimal demo, check these threads, they have a lot of valuable information and working examples:

Finally is worth noticing that Locomotive is not a GSAP Plugin. We try to keep these free forums focused on GSAP related questions.

 

You are welcome to explore our smooth scrolling solution ScrollSmoother:

https://gsap.com/docs/v3/Plugins/ScrollSmoother/

 

Hopefully this helps.

Happy Tweening!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...