有没有办法跟踪用户手指的持续时间,每1秒更改一次html内容。
我在一篇文章中找到了这个示例http://jsfiddle.net/7Z6hg/,但它与keydown有关。
$(function () {
var keyTimes = {};
$(document).keydown(function (e) {
if (keyTimes["key" + e.which]) {
return false;
}
keyTimes["key" + e.which] = new Date().getTime();
});
$(document).keyup(function (e) {
if (keyTimes["key" + e.which]) {
var x = new Date().getTime() - keyTimes["key" + e.which];
delete keyTimes["key" + e.which];
$("<p />").text("Held key " + e.which + " for " + x / 1000.0 + " seconds").appendTo("div");
}
});
});
触控设备是否有任何活动?
感谢您的帮助!
答案 0 :(得分:0)
Date-object
获取启动了哪个活动的Date
+(Unary plus)
获取Date-object
1000
将返回seconds
var elem = document.getElementById('elem');
var date;
elem.addEventListener('touchstart', function() {
date = +new Date();
});
elem.addEventListener('touchend', function() {
var diff = +new Date() - date;
console.log((diff / 1000).toFixed(2) + ' seconds');
});
&#13;
#elem {
width: 100%;
height: 200px;
background-color: green;
}
&#13;
<div id="elem">Element</div>
&#13;