Jump to content


direction of dragging !?...

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 guys :)


is there any way to find the direction of dragging !?

i mean that onDrag function return one of these value :

left / up-left / up / up-right / right / right-down / down / down-left !?


thanks in advance :)

Link to comment
Share on other sites

No, there aren't any built-in functions for determining that, but you can certainly discern it by comparing the current x/y with the previous x/y. 


I'm not sure if you're trying to figure out the direction since the start of the drag (total delta) or the moment-by-moment velocity, but here's a demo that shows both:



Notice that if you have ThrowPropsPlugin, you can get the current velocity of any property that it's tracking (and Draggable automatically turns on velocity tracking for whatever properties it's controlling), so I use those values in a simple formula. The nice thing about the ThrowPropsPlugin velocity tracking is that it uses some algorithms to more accurately discern things without getting tripped up by some funky variations that you'd likely stumble on if you were only comparing the current x/y to the previous one, depending how frequently the mousemove/touchmove is firing. 


If you don't like either of those solutions, something like Hammer.js might help (I've never used it, but I thought I heard that it does this sort of thing). 

  • Like 4
Link to comment
Share on other sites

Hi JACK  :)


WOW... that`s exactly what I've been looking for  :D .


thanks dude  :rolleyes:

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