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

What is Framer? Join the Community
Return to index
Noah Levin
Posted Jan 15 - Read on Facebook

Is there a quick / simple way to capture click position on mobile safari? event.x only seems to work on desktop framer / chrome. Basically I want:

Thing.on Events.Click, ->
print "Click Position X:" + event.x

Where instead of event, something that actually works

19 Comments

Cemre Güngör

event.offsetX

Cemre Güngör

not tested for mobile

Noah Levin

doesn't work on mobile. i only need something that works on mobile ;-)

Cemre Güngör

oh wait

Cemre Güngör

it's the touch position you're looking for

Cemre Güngör

the thing you want is in the touches array of the event

Cemre Güngör

touchEvent = Events.touchEvent event
touchEvent.clientX

Cemre Güngör

this is how draggable does it

Koen Bok

With touch on mobile you get multiple positions, because you can have multiple fingers touching the screen. You can loop through event.touches and grab the first one

https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent.touches

Cemre Güngör

btw most of my framer questions are generally answered in the source code

Koen Bok

Yeah, but this one threw me off the first time too.

Noah Levin

interesting. since that only works for touch (for example, in studio, that prints out the x including the scale value), I'm finding I need to write an if isMobile to capture them differently.

Amy Casillas

^ That took me forever to find when I needed it. Is it documented anywhere?

Jordan Robert Dobson

I use a little helper like this: http://cl.ly/ZIkN

Koen Bok

Amy: we rely on the standard browser events (for now) so not really in the Framer docs. Maybe I should add something for that until we roll our own sanitized events.

Jordan Robert Dobson

I agree Koen you should mention it until you roll your own... it's not clear what the path is... since everything is mostly rolled out by you guys, then in this one instance it's not... it's a bit frustrating. I've seen a few people hit this and come to me with questions about it.

Noah Levin

thanks!

Joshua Tucker

In my experience, page[X/Y] work on mobile. The position will be from [0, 0] starting from the top left side of the screen.

Layer.on Events.TouchStart, ->
print "Click Position:" + event.pageX

Read the entire post on Facebook