Jump to content
Search Community

Trigger —

mimeartist test
Moderator Tag

Go to solution Solved by ZachSaucier,

Recommended Posts

Hello,

 

I'm trying to make it so that when any item in a DIV is dragged, the whole parent DIV moves, but if just an item is clicked then it performs the click. I've made a codepen, but even the dragging is not working (it is in my real work)

 

The issue I have is that when the user clicks I want to get the attribute of the child item they've clicked on, even though I'm using trigger to make the parent draggable - I'm not sure why even the draggable isn't working in the codepen, other than perhaps my approach is all wrong... any ideas?

 

 

See the Pen abZExLM by mimeArtist (@mimeArtist) on CodePen

Link to comment
Share on other sites

  • Solution

Hey mimeartist. Normally you can just get the target by using this.target inside of Draggable's callbacks. But that gives you the Draggable target, not the element within the Draggable like what you're wanting. To get the element within the Draggable that was clicked on, you could either use .elementsFromPoint() with the pointerX and pointerY or add event listeners to the elements themselves (slightly better for performance). Demo of the latter:

See the Pen LYZewPq?editors=0010 by GreenSock (@GreenSock) on CodePen

Make sure to set allowEventDefault: true on the Draggable.

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