Jump to content
Search Community

find the ending location of a dragged object

Xristi test
Moderator Tag

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

Hi,

I need to get the current position of a dragged object on the completion of its tweening to another location. Here is my code:

 

Draggable.create("#firstNamedQuanDragImage1", {type:"x,y", bounds:"#nQL_DragDropGrid1", edgeResistance:0.5, cursor: "pointer",
  onDragEnd: function(e) {

if (this.hitTest(dropAreasArray[0], overlapThreshold)) {
      TweenMax.to(this.target, 0.5, {x:ecksPos, y:wyePos, onComplete:resetPermissionsArray_Target});
      //disAbleTiles2("2nd");
      studentAnswer = "EXPRESSION";
      removeCheckAnsButton1(false);
      function resetPermissionsArray_Target() {
        var firstTileLocus_X = $("#firstNamedQuanDragImage1").offset();
        var firstTileLeft = firstTileLocus_X.left;
        alert("location of first tile is: " + firstTileLeft);
      }

 

With this code I get the object location just fine but the tween ends and the object does not continue to its desired x/y position

If I remove the the onComplete and its function the tweening completes just fine but, obviously, no position info on the object.

Thank you for your invaluable assistance - I'm getting there! 

Link to comment
Share on other sites

You'd use this.x in the callback. this inside of Draggable callbacks returns the Drabble object itself unless you specifically set the scope using one of the on____Scrope (like onDragScrope) functions.

 

Modifying your code from above, you could get the values like so:

 

Draggable.create("#firstNamedQuanDragImage1", {type:"x,y", bounds:"#nQL_DragDropGrid1", edgeResistance:0.5, cursor: "pointer",
  onDragEnd: function(e) {
	console.log("x: " + this.x + ", y: " + this.y);
  }
});

 

  • Like 2
Link to comment
Share on other sites

Yes. I get the x/y coordinates but the the tween doesn't complete. When I put your "this.x..." in the onComplete function x/y comes back undefined. Why would the tween not complete? Some other part of my code must be wrong...

Link to comment
Share on other sites

Hello Zach,

 

I was able to arrive at a solution. Between your comments and OSUBlake's and Diaco's codepens for multiple drag objects and multiple targets I was able to piece together some code that worked. Thank you all for your time in helping all of us grateful GSAP users.

  • 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.
×
×
  • Create New...