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

What is Framer? Join the Community
Return to index
Giovanni Caruso
Posted Nov 12 - Read on Facebook

Is there any example on how to discriminate between single and double tap on the same button/layer? Tried with a counter but the logic doesn't flow as expected (i.e. counter += 1 on click event. if counter == 1 > something happens and counter goes to 0; if counter == 2 > ... but this second event never happens). Thanks for your help!

13 Comments

Andreas Mitschke

Show your code,maybe hidden logic failure.

Giovanni Caruso

Hi Andreas Mitschke. Here is an example:

counter = 0

iconLayer.on Events.Click, ->
>>>>counter += 1
>>>> if counter == 1
>>>>> print "this is the single tap"
>>>>> counter = 0
>>>>else if counter == 2
>>>>>> print "this is the double tap"
>>>>>> counter = 0

Andreas Mitschke

well, in this case the else will never fire as you already catch the first "if" the moment you click once and in that you reset everything so yeah logic error here.

I'm not sure if there is jquery support in studio, there you can simply use a function called dblclick.

Otherwise you can try something like this flag:
dClick = false
iLayer.on Events.Click ->
if (!dClick)
...
return dClick = true
else if (dClick)
...

Not sure for coffeescript syntax, don't use coffeescript.

Benjamin Den Boer

Andreas Mitschke

okay, so there is jquery support in studio ^^

Giovanni Caruso

Cool! :) Thank you! (how to discriminate between single and double clicks on the same layer? Since using 'dblclick' doesn't allow me to rely on the Events.Click)

Benjamin Den Boer

So "dblclick" is actually included in JavaScript, but not officially part of the DOM specification. ("DOM Level 0" feature.)

Stephen Crowley

Is using Hammer.JS out of the question?

Andreas Mitschke

Oh is it... well, thanks for that info. Just knew it from some years ago...

Giovanni Caruso

Stephen Crowley: ...could be an option. I'll give it a try. Thank you guys for the invaluable help (...as usual).

Stephen Crowley

Great! I'll just include this Hammer/FramerJS sample if you need it: http://cl.ly/0V1X2u2f0513

Alexis Morin

Benjamin, that line works nicely when testing in Framer.app or in a desktop browser but it seems like on Android and iOS it doesn't fire.

Benjamin Den Boer

Hey Alexis, ah yeah, I see. Probably not supported by mobile browsers / touch events. Since it's not officially included in the DOM specification, you may not want to rely on it too much either.

Read the entire post on Facebook