Jump to content
Search Community

Draggable: Cancel Drag?

jceddy test
Moderator Tag

Go to solution Solved by GreenSock,

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

I have some code that checks conditions in the onDragStart handler. I'd like to be able to cancel the drag if a set of conditions are not met. I had assumed that returning false from handler would do it, but was wrong. Is there any clean way to cancel a drag in this case?

 

Link to comment
Share on other sites

  • Solution

Yep, Diaco is right, but technically you are supposed to pass in the event. Here's an excerpt from the docs:

 

You may force the Draggable to immediately stop interactively dragging by calling endDrag() and passing it the original mouse or touch event that initiated the stop - this is necessary because Draggable must inspect that event for various information like pageX, pageY, target, etc. You cannot callendDrag() without passing that original event.

 

 

So it should be as simple as:

Draggable.create('.mas',{
  onPress:function(e){ if(!X){ this.endDrag(e) } }
});
  • Like 3
Link to comment
Share on other sites

The issue with calling endDrag() is that it triggers the onDragEnd handler, which does other processing I want to avoid in this case.

 

I suppose I could add something to the event object to let the handler know that I ended it due to my checks (as opposed to it being ended by the user letting up on the mouse button).

 

Edit:

That's what I ended up doing. There are a couple situations that just adding some info to the event object being propagated helped me solve.

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