Sometimes it's useful to know which direction an element is dragged (left | right | up | down | left-up | left-down | right-up | right-down), or maybe you'd like to know which direction it is compared to another element. That's precisely what getDirection()
is for. You can pass any of the following as the parameter to control its behavior:
"start"
(the default) - measures from wherever the drag began."velocity"
(requires ThrowPropsPlugin!) - measures the moment-by-moment direction of the drag. For example, maybe the user dragged really far to the right, but then they start dragging to the left for a brief moment - it's still to the right of the starting position, but it's current velocity is moving to the left. That's what "velocity" measures.[element]
- if you pass an element, it'll return the direction from that element's center to the Draggable's center.
Video
Demo
See the Pen Draggable with direction sensing by GreenSock (@GreenSock) on CodePen.