Handle Long Press/Tap Event In JavaScript – long-press-event

long-press.js is a small JavaScript library which detects and handles the long press/tap event on a specific DOM (or the whole document). Supports both desktop and mobile.

How to use it:

Import the long-press.js library into your html document.

<script src="dist/long-press.min.js"></script>

Attach the long press/tap event handler to a specific element.

var el = document.getElementById('demo');

el.addEventListener('long-press', function(e) {
  // do something
});

Or attach the event handler to the whole document.

document.addEventListener('long-press', function(e) {
  // do something
});

Customize the time delay in milliseconds. Default: 1.5s.

<div id="demo" data-long-press-delay="500">Press and hold me for .5s</div>

Changelog:

v2.5.2 (04/21/2026)

  • Bugfixes

v2.5.0 (04/27/2024)

  • Bugfix

v2.4.6 (02/25/2023)

  • Bugfix

v2.4.4 (05/25/2021)

  • update

v2.4.2 (11/16/2020)

  • suppress click event bug

v2.4.1 (11/15/2020)

  • Click event no longer fires after long-press event

v2.1.0 (09/23/2019)

  • Added possibility to forward clientX and clientY values

v2.0.1 (09/08/2019)

  • removed disable context menu, causes problems on android devices

v2.0.0 (08/29/2019)

  • replaced setTimeout with requestAnimationFrame for more accurate timing

v1.0.7 (08/28/2019)

  • disabled logging

v1.0.6 (07/02/2019)

  • refactored code and added useCapture=true for events

03/21/2018

  • fixed IIFE Webpack bug

02/02/2018

  • renamed to long-press-event

09/14/2018

  • v1.0.2

The post Handle Long Press/Tap Event In JavaScript – long-press-event appeared first on CSS Script.


Discover more from RSS Feeds Cloud

Subscribe to get the latest posts sent to your email.

Discover more from RSS Feeds Cloud

Subscribe now to keep reading and get access to the full archive.

Continue reading