long-press-event | Adds long-press event to the DOM in 1k of pure JavaScript
kandi X-RAY | long-press-event Summary
kandi X-RAY | long-press-event Summary
Adds `long-press` event to the DOM in 1k of pure JavaScript
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of long-press-event
long-press-event Key Features
long-press-event Examples and Code Snippets
Community Discussions
Trending Discussions on long-press-event
QUESTION
I'm building an app in Cordova and, as many apps have, I'm trying to implement long-press events that occur after holding down on an element.
I'm using https://github.com/john-doherty/long-press-event which fires a CustomEvent called 'long-press' after holding down on an element for 1.5 seconds.
I have an element I'd like to put both a 'Click' listener and a 'long-press' listener on, similar to many mobile apps such as photo galleries or email that react differently between a click and a long-press event.
The long-press event does fire, but the 'Click' event also fires every time and I can't find how or when I should try to stop it from firing. I've tried several placements of stopDefault()
and stopPropogation()
to no avail.
The HTML with a listener is
...ANSWER
Answered 2019-May-21 at 02:31Propagation is not the problem here - it's the fact that a long click event and a regular click event are actually the same thing, so they both fire. They're triggered because you do mouse down and then mouse up. The fact that there's a longer wait between the 2 events does not stop the regular click from being fired.
The simplest way to handle this would be to set a flag that indicates whether the long-click event has been triggered, like this...
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install long-press-event
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page