Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
pranastons

LocomotiveScroll and ScrollTrigger - error when onLeaveBack and locoScroll.scrollTo

Recommended Posts

Help! I need scroll to 'some_element' when i leave some-section. For this I used event onLeaveBack. (

onLeaveBack: () => locoScroll.scrollTo('.some_element') ,

) and I get this error
(

ScrollTrigger.js:453 Uncaught TypeError: Cannot read property 'update' of undefined
    at _updateAll (ScrollTrigger.js:453)
    at eval (locomotive-scroll.esm.js:401)
    at Array.forEach (<anonymous>)
    at _default.checkEvent (locomotive-scroll.esm.js:398)
    at _default.dispatchScroll (locomotive-scroll.esm.js:356)
    at _default.checkScroll (locomotive-scroll.esm.js:241)
    at _default.checkScroll (locomotive-scroll.esm.js:2043)
    at eval (locomotive-scroll.esm.js:1995)

)
If I used event onEnter - all ok, but I need do scroll when I scrolling up

Link to post
Share on other sites

What version of ScrollTrigger are you using? Can you please provide a minimal demo? It's just super difficult to troubleshoot blind :)

 

Also, you don't have once: true, do you? 

Link to post
Share on other sites

I can resolve this problem like this (

onEnterBack: () => {);
                    locoScroll.off("scroll"ScrollTrigger.update);
                    locoScroll.scrollTo('.some_element'0700);
                    locoScroll.on("scroll"ScrollTrigger.update);
                }

)
but I think than but I think that this no right (it's a crutch)

 

I use gsap v - 3.4.2

Link to post
Share on other sites

That looks to me like you're creating a race condition that'll crash the browser because inside your ScrollTrigger's update, you're forcing the LocomotiveScroll to a totally different value which will update the ScrollTrigger which will update the LocomotiveScroll and around and around you go. It's like an infinite loop; a logic problem. See what I mean? So yes, if you want to escape the logic problem, you'd need to remove the listener like you did in your proposed fix. 

  • Like 1
Link to post
Share on other sites

Thank. I think I understand what you mean. 
But I don't understand why such an error does not occur on the event onEnter ???

Link to post
Share on other sites
4 hours ago, pranastons said:

I don't understand why such an error does not occur on the event onEnter ???

onEnter fires once before the new value is set; there's no loop. An onUpdate that changes the value will continuously fire in a loop.

Link to post
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.

×