Jump to content

Joe Hakooz

Draggable Revert to Original Position

Go to solution Solved by Diaco,

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



Link to comment
Share on other sites

  • Solution

Hi Joe Hakooz  :)


Yep , pls try like this :

var StartX , StartY ;
Draggable.create("#myDiv", {
onPress:function(){  StartX = this.x;  StartY = this.y;   },
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)



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