Jump to content
Search Community

Uncaught error when using ScrollToPlugin

petero test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi,

 

I'm using the ScrollTo plugin to scroll elements into view, which works fine for a few clicks, but then goes into an infinite loop with error "Uncaught TypeError: Cannot read property 'y' of undefined" on TweenMax.js line 2008:

 

a[0] = new Segment(values[0][p], 0, 0, values[(l < -1) ? 0 : 1][p]);

 

l is -1, but values[1] is undefined.

 

I'm using TweenLite.to(window, 2, {scrollTo:{y:y}, ease:Power2.easeOut}), where my y is the offsetTop of an element.

 

Is there any way to trap that error? Putting a try/catch around the Tween doesn't help.

 

 

Link to comment
Share on other sites

Hm, something seems a bit fishy. That code you referenced has nothing to do with ScrollToPlugin - it's in BezierPlugin. It'd be SUPER helpful if you could provide a sample codepen or jsfiddle so that we can reproduce the error ourselves and inspect what's happening. It almost sounds like you're feeding values into a bezier tween but one of them is missing a property, like:

bezier:[ {x:0, y:20}, {x:10} ] //notice the 2nd object is missing the "y" value!

That's just a guess - it's tough to troubleshoot blind but hopefully that's at least slightly helpful :)

  • Like 2
Link to comment
Share on other sites

Thanks. I'll try to make a codepen, but I think it's all too integrated with the full app to simplify.

 

But what you said is interesting, in that I do have a separate bezier animation that will trigger when a particular element is scrolled into view, so technically, that could happen during the scrollTo. I'll disable the bezier & see what happens.

 

Thanks,
Peter
Link to comment
Share on other sites

Glad you solved it. To be clear, though, the problem [most likely] has nothing to do with whether or not you trigger the bezier via scrolling. It sounds like you just have a malformed tween. Tough to troubleshoot blind, but I'd bet you've just got some funky data being fed into the bezier, that's all. 

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