views:

20

answers:

1

Hi there.

Is there any way to pass to deactivate: whether an element was dropped or not?

I want to stop an animation if the element wasn't dropped, but was let go (ie: deactivate without drop), but I want it to carry on if the element was dropped correctly.

Thanks

A: 

I'm not sure if this is the best way, but it works:

I'm assuming you want to do this multiple times i.e. Keep animating while it is dropped correctly and if it is dragged out again and not dropped then cut the animation.

I would start by adding a parameter to the item being dragged which would indicate whether it is inside the target or not. e.g. var over_target = false;

When activate is called start the animation.

If the over event occurs the set over_target = true; if out event occurs then set over_target = false;

When deactivate is called you only need to check if over_target == false then stop the animation.

xiaohouzi79
basically you're saying set a global variable... hmm, I like that idea. :) thankk you.
Thomas Clayson
@Thomas it's not a global variable. From memory you can set variables on the draggable either through extending the options or some other way (sorry it's been 6 months since I had an in-depth look at draggables). So the variable stays with the object.This should be quite easy to research. But if you need help let me know.
xiaohouzi79
hmm, oh right ok well - I'll look into it and get back to you if I need some help. You're saying I should be able to set something like `ui.draggable.over_target`?
Thomas Clayson
I did some (incomplete) research this afternoon. You should be able to pass any variable in via the options so when you make the function call you can pass in any option like foo: 'bar' in the options list and using the getter/setter same as you do with any other options you should be able to retrieve/set the value
xiaohouzi79