This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Joshua Dern
Posted Aug 18 - Read on Facebook

Hey... Does anyone know how to grab the coordinates of the touch event? I'm trying to use clientX and clientY but they seem to be behaving oddly - the coordinate i get back is way off from the actual event and I want to calculate the distance of a swipe. Is there a better way to get this? Otherwise I'm thinking I'll just use Hammer JS to get a swipe.

11 Comments

Mike Feldstein

When i calculate distances i usually just grab the start position on TouchDown and compare the current position to that. That way the absolute position doesn't matter, just relative to the original touch.

Jordan Robert Dobson

Yeah a few values like this attached to those events like is in Hammer would be so helpful.

Mike Feldstein

You mean adding deltaX to events? I think that would be pretty useful. It's easy to do manually but would be nice to not have to write that code every time.

Koen Bok

I'm all for adding it. Something like layer.draggable.deltaX|deltaY?

Alex Hazel

Where are the x,y coordinates of a draggable layer calculated from? Its origin or its center? (top left corner as opposed the center point of the layer)

Mike Feldstein

layer.draggable.deltaX/Y would definitely be useful, could we also add it to TouchMove events? I find myself rewriting draggable functionality when i want to do snapping and stuff.

Koen Bok

Yeah I was wondering if we should add it to the event or as properties of the layer.draggable that is being dragged. Both would be easy to access.

Jordan Robert Dobson

I could see a use for both instances.

Tisho Georgiev

+1 for adding it to the event, although adding properties to the event object is a pain in the ass. A hammer-like event.gesture object for arbitrary info (delta, angle, velocity) would be great.

Koen Bok

That would be lovely. Let's track what we want here: https://github.com/koenbok/Framer/issues/107

This will be fun to make, and also a bit stealable from other projects. Pull requests welcome :-)

Ed Chao

I would love to have this. I agree with Mike Feldstein, writing that snippet each time gets repetitive. I vote for attaching it to the event. Seems like a more general/abstract solution.

Read the entire post on Facebook