IT Blog

  • Blog
  • Technology
    • Technology
    • Architecture
    • CMS
    • CRM
    • Web
    • DotNET
    • Python
    • Database
    • BI
    • Program Language
  • Users
    • Login
    • Register
    • Forgot Password?
  • ENEN
    • 中文中文
    • ENEN
Experience IT
In a World of Technology, People Make the Difference.
  1. Home
  2. Technology
  3. Handling long-press event

Handling long-press event

2018-05-12 914 Views 0 Like 0 Comments

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.

Problem:

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

Solution:

  • 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
$.each($US.file_id,(e,v)=>{
    $("#"+v).off(touchstart);
    $("#"+v).on(touchstart,$.proxy(()=>{
       timer = setTimeout($US.deleteFile.bind(null,v), 800);
    },null,e,v));
 
    $("#"+v).on(touchend,()=>{
       clearTimeout(timer);
    });
});

Ref: Passing parameters to event handler, setTimeout

Project: UService

Loading

error
fb-share-icon
Tweet
fb-share-icon
IT Team
Author: IT Team

Tags: None
Last updated:2018-05-12

IT Team

This person is lazy and left nothing

Like
< Previous
Next >

Comments

Cancel reply
Newest Hotspots Random
Newest Hotspots Random
Rich editor not working Making web page scroll down automatically Getting data from Dapper result All Unicode Chars How to keep and display contact form 7 data Common Regular Expressions
WordPress Sitemap Query Sending mail from SSIS How to keep and display contact form 7 data Common Regular Expressions All Unicode Chars JQuery DataTable.js customization
Categories
  • Architecture
  • BI
  • C#
  • CSS
  • Database
  • DotNET
  • Hosting
  • HTML
  • JavaScript
  • PHP
  • Program Language
  • Python
  • Security
  • SEO
  • Technology
  • Web
  • Wordpress

COPYRIGHT © 2021 Hostlike IT Blog. All rights reserved.

This site is supported by Hostlike.com