有一个事件侦听器,它由"touchmove“触发并执行一个函数。一切都井井有条。
然而,在我的理解中,该函数每隔(比如说) 500ms触发一次,这是非常慢的频率。
"touchmove“如何每隔300ms或100ms触发函数?
//this event listener is very slow
canvas.addEventListener('touchmove', draw_fn, false);
function draw_fn(e) {
getTouchPos(e);
drawDot(canvas,touchX,touchY,12);
event.preventDefault();
}
// tried to register touchmove with a bigger frequency
window.requestAnimFrame = (function (callback) {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimaitonFrame ||
function (callback) {
window.setTimeout(callback, 20); //or 200 or 100 or 50 or...
};
});发布于 2019-09-22 12:54:09
我找到了这个教程
http://www.javascriptkit.com/javatutors/touchevents3.shtml
这是一种不同的方法(链接是第3部分,您可能还需要阅读第1部分和第2部分)。您可以选择传递的点的数组,而不是从事件中拾取touchx和y。这将为您提供所需的粒度。
优秀的教程,有大量关于触摸事件属性的详细信息
https://stackoverflow.com/questions/58044010
复制相似问题