在javascript中获取触摸的持续时间 [英] get the duration of a touch in javascript

查看:112
本文介绍了在javascript中获取触摸的持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在ios设备上使用javascript获取触摸的持续时间(如果可能的话还可以使用其他设备)?我想区分长按和iphone webapp上的短按点击。

Is it possible to get the duration of a touch using javascript on ios devices (and others if possible)? I would like to differentiate a long press from a short "click" press on an iphone webapp.

感谢您的输入:)

推荐答案

$('#element').each(function() {

   var timeout,
       longtouch;

   $(this).bind('touchstart', function() {
      timeout = setTimeout(function() {
          longtouch = true;
      }, 1000);
   }).bind('touchend', function() {
       if (longtouch) {
          // It was a long touch.
       }
       longtouch = false;
       clearTimeout(timeout);
   });

});

jsFiddle

小提琴适用于长按

这篇关于在javascript中获取触摸的持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆