Count seconds on button long press in javascript

Kirankumar Dafda

I want to count seconds that how much time the button is pressed (long press) at a time using javascript, is there any function or event which fires at the time of long press of button?

Ben Fortune

You need to mix mousedown and mouseup events in order to achieve what you want.

Something like this:

var timer = 0,
    timerInterval,
    button = document.getElementById("button");

button.addEventListener("mousedown", function() {
  timerInterval = setInterval(function(){
    timer += 1;
    document.getElementById("timer").innerText = timer;
  }, 1000);
});

button.addEventListener("mouseup", function() {
  clearInterval(timerInterval);
  timer = 0;
});
<button id="button">Button</button>
<div id="timer">0</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Javascript: Detecting a long press

From Dev

Detect power button long press

From Dev

Button tap and long press gesture

From Dev

Volume Button long press event

From Java

Disable Long Press back Button (callout menu)

From Dev

Button Long Press Listener in Android jetpack compose

From Dev

Deleting the text in UITextFiled when long press on a button

From Dev

Camera button long press event in windows tablet

From Dev

Trigger a button press within a few seconds of opening that activity window

From Dev

Trigger a button press within a few seconds of opening that activity window

From Dev

Button click requires double click or long-press on mobile

From Dev

How to handle a long press on button in a waitkey function of bash script?

From Dev

Long Press Recognize Gesture via Button - Swift 3

From Dev

button press makes javascript reload page unintentionally

From Dev

Dynamically deleting selected rows on button press in Javascript

From Dev

Run javascript on button press ASP.NET

From Dev

Arduino. count the number of button press then play sequence

From Dev

javascript click button if inactive for 60 seconds

From Dev

Javascript Disable button and reenable it after 5 seconds

From Dev

javascript click button if inactive for 60 seconds

From Dev

No Javascript event in iOS when lifting finger after long press?

From Dev

How to generate a unique id everytime I press a button in JavaScript

From Dev

Ajax Javascript Function to execute PHP Code on Button Press

From Dev

JButton long press event

From Java

Long press gesture on UICollectionViewCell

From Java

Flutter - PopupMenu on long press

From Dev

Drag after long press

From Dev

delete tableViewCell on long press

From Dev

Long press in UiAutomation

Related Related

  1. 1

    Javascript: Detecting a long press

  2. 2

    Detect power button long press

  3. 3

    Button tap and long press gesture

  4. 4

    Volume Button long press event

  5. 5

    Disable Long Press back Button (callout menu)

  6. 6

    Button Long Press Listener in Android jetpack compose

  7. 7

    Deleting the text in UITextFiled when long press on a button

  8. 8

    Camera button long press event in windows tablet

  9. 9

    Trigger a button press within a few seconds of opening that activity window

  10. 10

    Trigger a button press within a few seconds of opening that activity window

  11. 11

    Button click requires double click or long-press on mobile

  12. 12

    How to handle a long press on button in a waitkey function of bash script?

  13. 13

    Long Press Recognize Gesture via Button - Swift 3

  14. 14

    button press makes javascript reload page unintentionally

  15. 15

    Dynamically deleting selected rows on button press in Javascript

  16. 16

    Run javascript on button press ASP.NET

  17. 17

    Arduino. count the number of button press then play sequence

  18. 18

    javascript click button if inactive for 60 seconds

  19. 19

    Javascript Disable button and reenable it after 5 seconds

  20. 20

    javascript click button if inactive for 60 seconds

  21. 21

    No Javascript event in iOS when lifting finger after long press?

  22. 22

    How to generate a unique id everytime I press a button in JavaScript

  23. 23

    Ajax Javascript Function to execute PHP Code on Button Press

  24. 24

    JButton long press event

  25. 25

    Long press gesture on UICollectionViewCell

  26. 26

    Flutter - PopupMenu on long press

  27. 27

    Drag after long press

  28. 28

    delete tableViewCell on long press

  29. 29

    Long press in UiAutomation

HotTag

Archive