Jump to content
Search Community

direction of dragging !?...

Diaco 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

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:

http://codepen.io/GreenSock/pen/zyxgh?editors=001

 

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

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