Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture "tap" event with pure JavaScript

Tags:

javascript

How can I capture a user's "tap" event with pure JS? I cannot use any libraries, unfortunately.

like image 452
Dan Ovidiu Boncut Avatar asked Nov 13 '12 09:11

Dan Ovidiu Boncut


People also ask

What is EventListener in JavaScript?

An event listener is a procedure in JavaScript that waits for an event to occur. The simple example of an event is a user clicking the mouse or pressing a key on the keyboard.

What is onTouchStart?

onTouchStart start is a touch event which fires when the user touches the element. onClick is a mouse event which fires when user clicks on the element.

What is the use of Touch_move?

The touchmove event is used to execute a script when the user moves the finger across the screen. It works only on touch screen devices and triggers once for every movement and continues to trigger until the finger is released.

How do you call an event in JavaScript?

Syntax. element.addEventListener(event, function, useCapture); The first parameter is the type of the event (like " click " or " mousedown " or any other HTML DOM Event.) The second parameter is the function we want to call when the event occurs.


1 Answers

The click event is triggered on mouse click as well as on a touch click.

The touchstart event is triggered when the screen is touched.

The touchend event is triggered when the touch ends. If the default action is prevented, a click event will not trigger.

http://www.w3.org/TR/touch-events/

like image 86
John Dvorak Avatar answered Sep 19 '22 15:09

John Dvorak