Jump to content
Search Community

Delete draggable item when out of bounds

johnnyqueue 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 there,

 

Just starting out with Draggable and am having some fun.  However, I'm trying to do something that I'm unable to figure out and am hoping someone can help me out.

 

I am trying to delete/remove/kill a draggable item when it is dragged out of bounds.  I'm not sure which event to use, nor how to delete/remove/kill active draggable item.

 

I am using this CodePen as the basis for my experimentation:  

 

See the Pen Jlfsq by rhernando (@rhernando) on CodePen

 

 

 Any help is appreciated

Johnny

Link to comment
Share on other sites

Hi and welcome to the GreenSock forums,

 

There isn't an onOutOfBounds event or anything similar in the API that will detect when an element goes out of bounds for you but there are enough hooks to whip something up. You would just have to run your own logic onDrag to see if the element has gone beyond the bounds.

Fortunately there are values like minX, maxX, minY and maxY that make it relatively straightforward to know what the bounds values are.

 

I got the solution from a much more advanced demo from Jack that progressively fades out the element as it leaves the bounds. See that here and look at the code:

 

See the Pen irzvd?editors=1010 by GreenSock (@GreenSock) on CodePen

 

Checking to see if the element is fully outside the bounds is not so bad, you just have to check on every up, down, right and left. Sort of like:

 

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

 

 

 

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