What is the best way to handle touch/pointer events on a surface tablet? I find its behavior quite confusing. I wrote a script that just set all the event handlers to figure out how the events are fired (setting native event handlers, using jQuery for the UI):
$.each([
"touchstart","touchmove","touchend",
"mousedown","mousemove","mouseup",
"pointerdown","pointermove","pointerup",
"MSPointerDown","MSPointerMove","MSPointerUp"
], function(i,eventname) {
tester.addEventListener(this, function(e) {
msg(eventname,e);
if ($("#prevent").is(":checked")) {
e.preventDefault();
}
if ($("#stop").is(":checked")) {
e.stopPropagation();
}
if ($("#stopimmediate").is(":checked")) {
e.stopImmediatePropagation();
}
}, false);
});
Using the mousepad or desktop IE11, everything is fine. All three events (mouse, pointer, MSPointer) are fired in the expected order: down, move, up.
But, when I use the tochscreen
- at first a pointermove fires, then pointer down. On the screen a rectangle appears around my finger.
- repeated move events are firing while not moving my finger
- firing no further events when I move my finger
- pointerend event when removing finger
What am I doing wrong? Calling preventDefault, stopPropagation or stopImmediatePropagation does not change this behavior. Setting the css pointer-events: none; disables all events.