Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Joe Hakooz

Draggable Revert to Original Position

Recommended Posts

Hello,

I was wondering if Draggable has a built in way to revert back to its original position on release?

 

For example, if I drag an item and it fails a hitTest on drop, then tween back to the starting point. Just like jQueryUI's draggable. 

 

If that functionality is not built in I will probably just keep track of the x,y on drag start and send it home if it fails the hit test on drag end, unless someone has a better idea...

 

Thanks!

Link to comment
Share on other sites

Hi Joe Hakooz  :)

 

Yep , pls try like this :

var StartX , StartY ;
Draggable.create("#myDiv", {
onPress:function(){  StartX = this.x;  StartY = this.y;   },
onRelease:function(){
if ( yourLogic ) { TweenLite.to( this.target , 1 , { x:StartX , y:StartY }) }
}
});
  • Like 2
Link to comment
Share on other sites

Thanks Diaco... again!

 

For the record, onDragStart's this.x and this.y include the minimumMovement pixels. So instead of reverting to 0,0 it might return to 9,3 depending on how fast you dragged the element. 

 

Instead of onStartDrag I used onPress which gives me the desired pixels BEFORE minimumMovement kicks in. 

  • Like 1
Link to comment
Share on other sites

Diaco beat me to it (again), but yeah, Draggable does not have a built in sendMeHome() function (although I like the idea). So the best approach is to record the start x and y yourself.

 

I regret this is too little too late, but we have a demo that pretty much does what you need(ed)

 

http://codepen.io/GreenSock/pen/Pqwxvw

  • Like 2
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.
×