getting touchy - an introduction to touch and pointer events / future of web apps / london...

148

Upload: patrick-lauke

Post on 09-May-2015

4.294 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 2: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 3: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 4: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 7: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

mouseover > mousemove* > mousedown >

(focus) > mouseup > click

Page 8: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

mouseover > mousemove > mousedown >

(focus) > mouseup > click

mousemove > mousedown > (focus) >

mouseup > click

mouseout > (blur)

focus/blur

mouseout

Page 9: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 10: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 11: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 14: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 16: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 18: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 20: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

touchstart

touchmove

touchend

touchcancel

touchenter

touchleave

Page 23: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

touchstart > [touchmove]+ > touchend >

mouseover > mousemove > mousedown >

(focus) > mouseup > click

Page 24: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

touchstart > [touchmove]+ > touchend > mouseover >

mousemove > mousedown > (focus) > mouseup > click

touchstart > [touchmove]+ > touchend > mousemove >

mousedown > (focus) > mouseup > click

mouseout > (blur)

touchmove touchend

touchmove

Page 25: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

mouseover > mousemove > touchstart > touchend > mousedown >

mouseup > click

touchstart > mouseover > mousemove > mousedown > touchend >

mouseup > click

Page 26: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 27: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 28: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 31: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 32: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 33: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 34: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

if ('ontouchstart' in window) {

/* some clever stuff here */

}

Page 35: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

/* common performance “trick” */

var clickEvent = ('ontouchstart' in window ?

'touchend' : 'click');

blah.addEventListener(clickEvent,

function() { ... }, false);

Page 36: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 38: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

if ('ontouchstart' in window) {

/* browser supports touch events

but user is not necessarily

using touch (exclusively) */

}

Page 39: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 40: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 42: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

touchstart > touchend > mouseover > mousemove > mousedown > mouseup > click

Page 43: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

mouseover > mousedown > mousemove > mouseup > click

Page 44: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

focus > click

Page 45: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 46: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

focus > touchstart > touchend > mouseover > mousemove > mousedown

blur > mouseup > click

Page 47: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

focus > touchstart > touchend > mouseover > mousemove > mousedown

blur > mouseup > click

Page 48: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

focus > blur > mousedown > mouseup > click > focus(?)

Page 49: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 50: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 51: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

/* doubled-up event listeners */

foo.addEventListener('touchstart',

someFunction, false);

foo.addEventListener('click',

someFunction, false);

Page 52: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

/* doubled-up event listeners */

foo.addEventListener('touchstart',

function(e) {

/* prevent delay+mouse events */

e.preventDefault();

someFunction();

/* or even e.target.click(); */

}, false);

foo.addEventListener('click',

someFunction, false);

Page 54: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

preventDefault

Page 55: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 58: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 63: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 65: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 67: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

touchstart > [touchmove]+ > touchend >

mouseover > mousemove* > mousedown >

(focus) > mouseup > click

Page 68: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

mousemove touchmove

Page 69: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

var posX, posY;

...

function positionHandler(e) {

posX = e.clientX;

posY = e.clientY;

}

...

canvas.addEventListener('mousemove',

positionHandler, false);

Page 70: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

var posX, posY;

...

function positionHandler(e) {

/* handle both mouse and touch? */

}

...

canvas.addEventListener('mousemove',

positionHandler, false);

canvas.addEventListener('touchmove',

positionHandler, false);

Page 71: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

interface MouseEvent : UIEvent {

readonly attribute long screenX;

readonly attribute long screenY;

readonly attribute long clientX;

readonly attribute long clientY;

readonly attribute boolean ctrlKey;

readonly attribute boolean shiftKey;

readonly attribute boolean altKey;

readonly attribute boolean metaKey;

readonly attribute unsigned short button;

readonly attribute EventTarget

relatedTarget;

void initMouseEvent(...);

};

Page 72: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

interface TouchEvent : UIEvent {

readonly attribute TouchList touches;

readonly attribute TouchList targetTouches;

readonly attribute TouchList changedTouches;

readonly attribute boolean altKey;

readonly attribute boolean metaKey;

readonly attribute boolean ctrlKey;

readonly attribute boolean shiftKey;

};

Page 73: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

interface Touch {

readonly attribute long identifier;

readonly attribute EventTarget target;

readonly attribute long screenX;

readonly attribute long screenY;

readonly attribute long clientX;

readonly attribute long clientY;

readonly attribute long pageX;

readonly attribute long pageY;

};

Page 74: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

var posX, posY;

...

function positionHandler(e) {

if ((e.clientX)&&(e.clientY)) {

posX = e.clientX;

posY = e.clientY;

} else if (e.targetTouches) {

posX = e.targetTouches[0].clientX;

posY = e.targetTouches[0].clientY;

e.preventDefault();

}

}

...

canvas.addEventListener('mousemove',

positionHandler, false );

canvas.addEventListener('touchmove',

positionHandler, false );

Page 75: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 77: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 79: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 81: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 83: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 85: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

touchmove

Page 86: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

touchmove

Page 87: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

requestAnimationFrame

setInterval

Page 89: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 90: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

interface TouchEvent : UIEvent {

readonly attribute TouchList touches;

readonly attribute TouchList targetTouches;

readonly attribute TouchList changedTouches;

readonly attribute boolean altKey;

readonly attribute boolean metaKey;

readonly attribute boolean ctrlKey;

readonly attribute boolean shiftKey;

};

Page 91: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

for (i=0; i<e.targetTouches.length; i++) {

...

posX = e.targetTouches[i].clientX;

posY = e.targetTouches[i].clientY;

...

}

Page 93: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

preventDefault()

Page 94: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

preventDefault()

Page 95: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 96: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

/* iOS/Safari has gesture events for size/rotation,

not supported in Chrome/Firefox/Opera,

not part of the W3C Touch Events spec. */

gesturestart, gesturechange, gestureend

e.scale, e.rotation

Page 97: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

/* with some trigonometry we can replicate these

from basic principles. */

var distance = Math.sqrt(Math.pow(...)+Math.pow(...));

var angle = Math.atan2(...);

Page 100: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 103: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 107: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 109: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

pointerover > mouseover >

pointerdown > mousedown >

pointermove > mousemove >

(focus) >

pointerup > mouseup >

pointerout > mouseout >

click

Page 110: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

pointerenter

pointerleave

gotpointercapture

lostpointercapture

Page 111: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

MSPointerDown

MSPointerMove

MSPointerUp

navigator.msPointerEnabled

navigator.msMaxTouchPoints

-ms-touch-action

Page 112: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

interface MouseEvent : UIEvent {

readonly attribute long screenX;

readonly attribute long screenY;

readonly attribute long clientX;

readonly attribute long clientY;

readonly attribute boolean ctrlKey;

readonly attribute boolean shiftKey;

readonly attribute boolean altKey;

readonly attribute boolean metaKey;

readonly attribute unsigned short button;

readonly attribute EventTarget

relatedTarget;

void initMouseEvent(...);

};

Page 113: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

/* Pointer Events extend Mouse Events

vs Touch Events and their completely new objects/arrays */

interface PointerEvent : MouseEvent {

readonly attribute long pointerId;

readonly attribute long width;

readonly attribute long height;

readonly attribute float pressure;

readonly attribute long tiltX;

readonly attribute long tiltY;

readonly attribute DOMString pointerType;

readonly attribute boolean isPrimary;

};

Page 114: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 115: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 116: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 119: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 120: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

preventDefault()

pointerdown

Page 121: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

touch-action: auto|none|[pan-x][pan-y]

Page 122: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

touch-action:none

Page 124: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

touch-action:none

Page 125: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 127: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

touch-action:none

Page 129: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 131: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

/* PointerEvents don't have the handy touch arrays,

so we have to replicate something similar... */

Page 132: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

/* PointerEvents don't have the handy touch arrays,

so we have to replicate something similar... */

var points = [];

switch (e.type) {

case 'pointerdown':

/* add to the array */

break;

case 'pointermove':

/* update the relevant array entry's x and y */

break;

case 'pointerup':

/* remove the relevant array entry */

break;

}

Page 134: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013

/* like iOS/Safari, IE10/Win has higher-level gestures,

but these are not part of the W3C Pointer Events spec.

Replicate these from basic principles again? */

Page 135: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 137: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 139: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 140: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013
Page 144: Getting touchy - an introduction to touch and pointer events / Future of Web Apps / London 24.10.2013