【问题标题】:Javascript touch-event: how to increase trigger frequency?Javascript touch-event:如何增加触发频率?
【发布时间】: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


    【解决方案1】:

    我找到了这个教程

    http://www.javascriptkit.com/javatutors/touchevents3.shtml

    这是一种不同的方法(链接是第 3 部分,您可能还需要阅读第 1 部分和第 2 部分)。无需从事件中获取 touchx 和 y,您可以获取经过的点数组。这应该会为您提供所需的粒度。

    优秀的教程,对触摸事件属性有详细的介绍

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-20
      • 1970-01-01
      • 2018-05-20
      相关资源
      最近更新 更多