3 ms·
Reviewing the test case code the basic bug seem to be that sometimes a touchend event won't fire when a secondary finger is lifted. You can make your code much
by SigmundA 14y ago
Reviewing the test case code the basic bug seem to be that sometimes a touchend event won't fire when a secondary finger is lifted.
You can make your code much more reliable by handling all touch events and looking that the touches or targetTouches respectively instead of incremental a total touch counter on each start and decrementing on each end. This causes even the slightest movement to trigger a touchmove event which and the entire current touch state is in touches within all the events. So changing your test like so gets close and you can at least see the use more clearly:
var i = 0;
var numTouches = 0;
var out = document.getElementById('out');
var indicator = document.getElementById('indicator');
function handleTouch( ev ) {
ev.preventDefault();
i++;
numTouches = ev.touches.length;
out.value += i + ': ' + ev.type + ', ' + numTouches + '\n';
indicator.style.backgroundColor
= (numTouches == 2) ? '#8e6' : '#fb7';
out.scrollTop = out.scrollHeight;
}
var ta = document.getElementById('ta');
ta.addEventListener('touchstart', handleTouch, false);
ta.addEventListener('touchend', handleTouch, false);
ta.addEventListener('touchmove', handleTouch, false);
ta.addEventListener('touchcancel', handleTouch, false);