Jump to content
Search Community

Draggable error in version 12 when using disable()

G. Scott test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

I'm trying to enable and disable Draggable and it is causing an error:

Uncaught Range Error: Maximum call stack size exceeded

 

It's a snippet I've used many times and only throws the error in version 12+. You can see it in action in the CodePen.

 

I'm using a matchMedia listener to trigger the Draggable div to enable on small screen, and disable on large. If you drag the browser window < 1024 you will see that it enables just fine. But if you drag it back out > 1025px wide, when it disables, it throws the error. Interestingly, if you don't actually interact with the draggable div, it won't throw the error. But if you enable it, then drag the element, and then disable it again, then you get the error. I checked and made sure the matchMedia listener is only firing when it changes, and not in any kind of loop. And again, if I switch to a version of Draggable < version 12, it works perfectly.

 

Hope the CodePen is ok... don't use that too much:-)

 

See the Pen yLQadBQ by g3logic (@g3logic) on CodePen

  • Like 1
Link to comment
Share on other sites

  • G. Scott changed the title to Draggable error in version 12 when using disable()
  • Solution

Great catch! Sorry about that - it's resolved in the next release which you can preview at https://assets.codepen.io/16327/Draggable3.min.js (you may need to clear your cache). We'll be pushing that live very soon.

 

It'd only happen if you had inertia enabled.

 

Thanks for the excellent minimal demo! That's super helpful. I wish everyone was as thoughtful when reporting an issue. 🙌 

Link to comment
Share on other sites

First of all, I have to confess that this is the first time I've included a codepen. I know it makes your life easier... I'm just usually up to my ears. But I'm glad I did this time and a little giddy that it wasn't something dumb that I was doing! 😅 Anyway, now that I see how easy it was I'll be sure to always include a codepen going forward.

 

With regards to gsap.matchMedia... yes I have used it VERY successfully! Didn't think to on this for some reason. Would it make more sense with Draggable? Would it reset the position of the element when Draggable was disabled? Or would I still need to set the x coordinate back.

 

Those GSAP utilities are sneaky powerful!

  • Like 2
Link to comment
Share on other sites

8 hours ago, G. Scott said:

With regards to gsap.matchMedia... yes I have used it VERY successfully! Didn't think to on this for some reason. Would it make more sense with Draggable? Would it reset the position of the element when Draggable was disabled? Or would I still need to set the x coordinate back.

Yep. All your previous code could be simplified to this: 

See the Pen vYQyNVp?editors=0010 by GreenSock (@GreenSock) on CodePen

 

Isn't that nice? :)

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