Jump to content
Search Community

Draggable out of sync when swapping elements

Jens De Muynck test
Moderator Tag

Recommended Posts

Hi,

 

This most likely has to do with the fact that you're making the reparenting of the elements (updating the DOM) in the onDrag callback. If I was you I'd do that in the onDragEnd and during the onDrag I just move the other elements around. In this cases is quite simple since they move a specific amount of pixels up/down (the height of the element being dragged. If all the elements have the same height is even easier.

 

Also you should try using Draggable's hitTest method in order to check if the dragged element is overlapping another from the collection:

https://gsap.com/docs/v3/Plugins/Draggable/static.hitTest()

 

Unfortunately I didn't had time to create a demo with my approach since this is not the simplest thing to achieve (not the most complex though, but definitely not simple), but hopefully this somehow helps.

Happy Tweening!

Link to comment
Share on other sites

Thanks for your reply!

 

I updated my codepen to only update the DOM in the onRelease method, and it worked like i expected it to. However, when i applied these changes in my project, I encountered a similar problem.

After further testing, i discovered that the issue is with the scroller parent, so I updated my codepen to closer resemble my project where the 'main' element is the scroller instead of the body.

Does Draggable not take a different scroller into account?

 

Updated codepen:

See the Pen NWmopxv by JensDeMuynck (@JensDeMuynck) on CodePen

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