【发布时间】:2019-09-21 20:53:47
【问题描述】:
有一个事件监听器,由“touchmove”触发并执行一个函数。一切都很整洁。
但是,据我了解,该功能每(比如说)500 毫秒触发一次,这是非常慢的频率。
“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...
};
});
【问题讨论】:
标签: javascript touch touch-event