Skip to main content

Imitate Long Press / Taphold On Desktop With jQuery

By May 22, 2017Blog, Javascript, jQuery
Allure Web Solutions Code Snippet

In this blog post I show how to imitate a long press/ taphold on the desktop. There’s not really any use cases for this that I can think of in the real world. The same technique could be applied to some HTML5 game I guess.

The JavaScript

(function(window, jQuery) {
  var $body = $("body"), $touchArea = $("#toucharea");

    .on("mouseup", $touchArea, function(e) {
      return false;
    .on("mousedown", $touchArea, function(e) {
      // Set timeout to imitate 1s press
      pressTimer = window.setTimeout(function() {
        // Perform some action after 1s press
      }, 1000);
      return false;

  function doAction(e) {
    // do something 
})(window, jQuery);
// Credits:


See the Pen Imitate Long Press / Taphold On Desktop With jQuery by Mike Doubintchik (@allurewebsolutions) on CodePen.


Author allure

More posts by allure

Leave a Reply

Designed by

best down free | web phu nu so | toc dep 2017