Jump to content
Search Community

Draggable swap positions

Arnold.Krumins 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 new to Greensock and am evaluating the api before I purchase a license. I must say i'm incredibly impressed!

 

One question.  How easy is it to swap positions when you drop an element onto another? Using Greensock's draggable demo

 

 

If I dragged the red box to the green box and dropped it. The green box would move to the red boxes original starting position

The red box would stay in the new position. Basically swapping locations.

 

Does anybody know the most efficient way to do this?

 

Cheers,

 

Arnold

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

Link to comment
Share on other sites

Hi Arnold.Krumins  :)

 

Draggable hitTest() logic's what you looking for :

 

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

 

http://greensock.com/docs/#/HTML5/Drag/Draggable/hitTest/

 

- pls check this out ,  I've just changed a bit the original codepen ( just onDrop function ) :

 

See the Pen xbOjpv by MAW (@MAW) on CodePen

 

- and i think this's another useful codepen for you :

 

sortable elements with GreenSock draggable : 

See the Pen eIDna by MAW (@MAW) on CodePen

  • Like 1
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...