JavaScript ontouchend和ontouchcancel不起作用?

时间:2018-09-01 20:57:25

标签: javascript ontouchevent

我有以下代码来响应触摸事件:

        ontouchstart = function (e) {
            socket.emit('touch', "START, " + String(e.touches[0].screenX) + ", " + String(e.touches[0].screenY ) + ", " + (Date.now() - start));
        }
        ontouchmove = function (e) {
            socket.emit('touch', "MOVE, " + String(e.touches[0].screenX) + ", " + String(e.touches[0].screenY ) + ", " + (Date.now() - start));
        }
        ontouchend = function (e) {
            socket.emit('touch', "END, " + String(e.touches[0].screenX) + ", " + String(e.touches[0].screenY ) + ", " + (Date.now() - start));
        }
        ontouchcancel = function (e) {
            socket.emit('touch', "CANCEL, " + String(e.touches[0].screenX) + ", " + String(e.touches[0].screenY ) + ", " + (Date.now() - start));
        }

但是它仅适用于触摸开始和移动,当我在iPhone上放开手指时,它无法跟踪休假。好吧,我想我可以尝试看看是否可以继续检查现有的触摸并在从触摸中删除触摸时将其记录下来,但是有没有更简单的方法,例如使此代码正常工作?

0 个答案:

没有答案