Share Posted June 9, 2015 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 More sharing options...
Share Posted June 9, 2015 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 }) } } }); 2 Link to comment Share on other sites More sharing options...
Author Share Posted June 10, 2015 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. 1 Link to comment Share on other sites More sharing options...
Share Posted June 10, 2015 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 2 Link to comment Share on other sites More sharing options...
Author Share Posted June 10, 2015 Thanks Carl. That demo will definitely come in handy! My new issue in another post is performing a hitTest on multiple elements. http://greensock.com/forums/topic/11870-draggable-hittest-multiple-elements/ Once I get that resolved I can forget about jQueryUI's less buttery draggable Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now