Jump to content

Search In
  • More options...
Find results that contain...
Find results in...

How can I trigger a Draggable 'onClick' event?

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



How can I manually trigger an 'onClick' event in a Draggable object? 


More specifically, I want to trigger it from within the  function called in reply to the 'onDragEnd' event.


Thanks !



Link to comment
Share on other sites

Can you help me understand the practical value of this? Why wouldn't you just call the function that the onCick would call? Why the round-about way of triggering it? 


The tricky thing about manually triggering an onClick event is that there's no actual event to associate with it, thus the "pointerEvent" wouldn't be accurate in that case. So if, for example, your onClick handler had logic that looked at the pointerEvent.target or pointerEvent.pageX or whatever, it would likely break. See what I mean? 


Perhaps there's a good practical use case for this, but I just can't seem to think of it. Maybe if you explain WHY you want to manually trigger an onClick, we can help offer a different solution. 

Link to comment
Share on other sites



I certainly understand your question :-).  I have a rather complex application hence I cannot give an example.  I noticed a strange behavior that happened when I was dragging an object, and that behavior disappeared after the user clicks on the object.  At first I tried to put the same code there is in the 'onClick' event in the 'onDragEnd' event but it didn't work... I was hoping to trigger the 'onClick' event as a workaround... I know it's not good practice, I suppose I have no choice but to figure out what was the bug that created that behavior and to fix it..


Anyways thank you for you concern and good will !



Link to comment
Share on other sites

Ah, okay. Yeah, I whole-heartedly endorse just putting in the hard work of chasing down the source of the problem. I know that can be a pain though, and sometimes you've got deadlines that make it so tempting to just slap a shot-in-the-dark "fix" :)


Make sure you're using the latest version of Draggable. 


If you can reproduce the problem you're running into inside of a codepen in its simplest form, we'd be happy to take a peek and see if we can offer any insight. 


Good luck!

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.