Handling long-press event

Image result for long press

On desktop, to handle long-press event, we can utilize mousedown/mouseup event, with setTimeout to control the time period of the mouse pressed.


However desktop browser support mousedown/mouseup event, but not touchstart/touchend event, while mobile behave the reverse way.


  • declare two valiables:
var touchstart = 'mousedown';
var touchend = 'mouseup';

check which event the browser support

if('ontouchstart' in document.documentElement){
    touchstart = 'touchstart';
    touchend = 'touchend'
  • Handling long press event
       timer = setTimeout($US.deleteFile.bind(null,v), 800);

Ref: Passing parameters to event handler, setTimeout

Project: UService

 426 total views

Author: Albert

Leave a Reply