Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
jceddy

Draggable: Cancel Drag?

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?

 

Share this post


Link to post
Share on other sites

I actually moved the check to onPress and just basically just disable then re-enable the Draggable if the check fails.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×