Jump to content
Search Community

Draggable - Returning the DOM element currently being dragged

caffrey75 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 there, 

 

Thanks for updating Draggable so quickly - works great in IE now :) 

 

My current problem is that I've got 5 DOM elements that are being made Draggable.  I was hoping that I could call a function using onDragStart and by passing through the parameters [this.target], I would be able to manipulate the DOM element that is currently being dragged.  

 

However, whenever I console.log out this.target - no matter what DOM element is being dragged - the return is always the last draggable element (i.e. 'drag_5').

 

Whilst I understand that Draggable can consist of an array of draggable elements, is there any way that I can identify which element is currently being dragged by using either something like [this.target] or by spitting out its position in the Draggable array?  

 

Cheers in advance :)

 

Link to comment
Share on other sites

Yep, each Draggable instance can only be associated with one element and that's referred to as its "target" property, so you should be able to just reference this.target inside your onDragStart. Here's a simple codepen demo: 

See the Pen b21ff61d20dcbdef0eda79caad8f2027 by GreenSock (@GreenSock) on CodePen

 

Ah fantastic, Jack, works like a dream! Thankyou :)

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