SlideShare a Scribd company logo
getting touchy
AN INTRODUCTION TO TOUCH EVENTS

Patrick H. Lauke / Sainté Mobile Days / Saint-Etienne / 22 November 2013
“how can I make my website
work on touch devices?”
you don't need touch events
browsers emulate regular mouse events
patrickhlauke.github.io/touch/tests/event-listener_mouse-only.html
patrickhlauke.github.io/touch/tests/event-listener_mouse-only.html
mouseover > mousemove* > mousedown >
(focus) > mouseup > click
*only a single “sacrificial” event is fired
emulation works,
but is limiting/problematic
1. delayed event dispatch
2. mousemove doesn't track
there are more (e.g. no concept of hover on touchscreens)
1. delayed event dispatch
2. mousemove doesn't track
patrickhlauke.github.io/touch/tests/event-listener_show-delay.html
patrickhlauke.github.io/touch/tests/event-listener_show-delay.html
1. delayed event dispatch
2. mousemove doesn't track
patrickhlauke.github.io/touch/particle/2
patrickhlauke.github.io/touch/particle/2
(bug in iOS7: moving finger does seem to scroll and fire multiple mousemove events?!)
“we need to go deeper...”
touch events
introduced in iOS 2.0, adopted in Chrome/Firefox/Opera
www.w3.org/TR/touch-events
touchstart
touchmove
touchend
touchcancel
touchenter
touchleave
patrickhlauke.github.io/touch/tests/event-listener_all-no-timings.html
patrickhlauke.github.io/touch/tests/event-listener_all-no-timings.html
touchstart > [touchmove]+ > touchend >
mouseover > mousemove > mousedown >
(focus) > mouseup > click
Browser/Android 4.3
(AppleWebKit/534.30)
mouseover > mousemove > touchstart > touchend > mousedown >
mouseup > click

Browser/Blackberry PlayBook 2.0
(AppleWebKit/536.2)
touchstart > mouseover > mousemove > mousedown > touchend >
mouseup > click
touch events
vs
limitations/problems
1. delayed event dispatch
2. mousemove doesn't track
1. delayed event dispatch
2. mousemove doesn't track
patrickhlauke.github.io/touch/tests/event-listener.html
patrickhlauke.github.io/touch/tests/event-listener.html
“how can we make it feel
responsive like a native app?”
react to events fired before
the 300ms delay...
interlude:
simple feature detection for
touch events
if ('ontouchstart' in window) {
/* some clever stuff here */
}
/* common performance “trick” */
var clickEvent = ('ontouchstart' in window ?
'touchend' : 'click');
blah.addEventListener(clickEvent,
function() { ... }, false);
don't make it touch-exclusive
if ('ontouchstart' in window) {
/* browser supports touch events
but user is not necessarily
using touch (exclusively) */
}
hybrid devices
touch + mouse + keyboard
Getting touchy - an introduction to touch events / Sainté Mobile Days / Saint-Etienne 22.11.2013
Getting touchy - an introduction to touch events / Sainté Mobile Days / Saint-Etienne 22.11.2013
Android + mouse – behaves like touch
touchstart > touchend > mouseover > mousemove > mousedown > mouseup > click
Android + keyboard – like desktop keyboard
focus > click
VoiceOver enables keyboard access on iOS
iOS + keyboard – similar to touch
focus > touchstart > touchend > mouseover > mousemove > mousedown
blur > mouseup > click
iOS + VoiceOver – similar to touch
focus > touchstart > touchend > mouseover > mousemove > mousedown
blur > mouseup > click
Android + TalkBack – keyboard/mouse hybrid
focus > blur > mousedown > mouseup > click > focus(?)
touch or mouse or keyboard
touch and mouse and keyboard
/* doubled-up event listeners */
foo.addEventListener('touchend',
someFunction, false);
foo.addEventListener('click',
someFunction, false);
/* doubled-up event listeners */
foo.addEventListener('touchend',
function(e) {
/* prevent delay + mouse events */
e.preventDefault();
someFunction();
/* or even e.target.click(); */
}, false);
foo.addEventListener('click',
someFunction, false);
github.com/ftlabs/fastclick
preventDefault
kills scrolling, long-press,
pinch/zoom
browsers working to remove
delay when possible
patrickhlauke.github.io/touch/tests/event-listener_user-scalable-no.html
patrickhlauke.github.io/touch/tests/event-listener_minimum-maximum-scale.html
Getting touchy - an introduction to touch events / Sainté Mobile Days / Saint-Etienne 22.11.2013
patrickhlauke.github.io/touch/tests/event-listener_user-scalable-no.html
[...] no more 300ms click delay, or double-tap zoom, on mobile websites
patrickhlauke.github.io/touch/tests/event-listener_user-scalable-no.html
iOS/Safari designed themselves into a corner
with “double-tap to scroll”
bugs.webkit.org/show_bug.cgi?id=122212
1. delayed event dispatch
2. mousemove doesn't track
patrickhlauke.github.io/touch/particle/2
patrickhlauke.github.io/touch/particle/2
(bug in iOS7: moving finger does seem to scroll and fire multiple mousemove events?!)
touchstart > [touchmove]+ > touchend >
mouseover > mousemove* > mousedown >
(focus) > mouseup > click
*mouse event emulation fires only a single mousemove
doubling up handling of
mousemove and touchmove
var posX, posY;
...
function positionHandler(e) {
posX = e.clientX;
posY = e.clientY;
}
...
canvas.addEventListener('mousemove',
positionHandler, false);
var posX, posY;
...
function positionHandler(e) {
/* handle both mouse and touch? */
}
...
canvas.addEventListener('mousemove',
positionHandler, false);
canvas.addEventListener('touchmove',
positionHandler, false);
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(...);
};

www.w3.org/TR/DOM-Level-2-Events/events.html#Events-MouseEvent
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;
};

www.w3.org/TR/touch-events/#touchevent-interface
interface Touch {
readonly attribute
readonly attribute
readonly attribute
readonly attribute
readonly attribute
readonly attribute
readonly attribute
readonly attribute
};

long
EventTarget
long
long
long
long
long
long

identifier;
target;
screenX;
screenY;
clientX;
clientY;
pageX;
pageY;

www.w3.org/TR/touch-events/#touch-interface
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 );
patrickhlauke.github.io/touch/particle/3
tracking finger movement
over time ... swipe gestures
patrickhlauke.github.io/touch/swipe
patrickhlauke.github.io/touch/swipe
patrickhlauke.github.io/touch/picture-slider
don't forget mouse/keyboard !
touchmove fires...a lot!
do absolute minimum on each
touchmove
(usually: store new coordinates)
heavy JavaScript on
requestAnimationFrame
setInterval
patrickhlauke.github.io/touch/touch-limit
why stop at a single point?
multitouch support
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;
};

www.w3.org/TR/touch-events/#touchevent-interface
for (i=0; i<e.targetTouches.length; i++) {
...
posX = e.targetTouches[i].clientX;
posY = e.targetTouches[i].clientY;
...
}
patrickhlauke.github.io/touch/tracker/multi-touch-tracker.html
iOS/iPad even preventDefault()
can't override 4-finger gestures
iOS7/Safari even preventDefault()
can't override back/forward swipe gestures
/* iOS/Safari has gesture events for size/rotation
not supported in Chrome/Firefox, not part of the
W3C Touch Events specification.
With some trigonometry we can replicate these
from basic principles. */
var distance = Math.sqrt(Math.pow(...)+Math.pow(...));
var angle = Math.atan2(...);
shinydemos.com/picture-organizer
touch events and
Internet Explorer...
blogs.msdn.com/...
www.w3.org/TR/pointerevents
not just some “not invented here”
new approach for IE10+
active development by Mozilla and
Chrome teams
...Apple?
but that's probably enough
for now...
pour en savoir plus:

rendez-vous à l'atelier
demain matin
@patrick_h_lauke
github.com/patrickhlauke/touch
slideshare.net/redux
paciellogroup.com
splintered.co.uk

More Related Content

What's hot (18)

PDF
Getting touchy - an introduction to touch and pointer events (1 day workshop)...
Patrick Lauke
 
PDF
Getting touchy - an introduction to touch and pointer events / Smashing Confe...
Patrick Lauke
 
PDF
Getting touchy - an introduction to touch and pointer events (complete master...
Patrick Lauke
 
PDF
Getting touchy - an introduction to touch and pointer events / Frontend NE / ...
Patrick Lauke
 
PDF
Getting touchy - an introduction to touch and pointer events / Workshop / Jav...
Patrick Lauke
 
PDF
Getting touchy - an introduction to touch and pointer events (Workshop) / Jav...
Patrick Lauke
 
PDF
Getting touchy - an introduction to touch and pointer events / Future of Web ...
Patrick Lauke
 
PDF
Getting touchy - an introduction to touch and pointer events / Sainté Mobile ...
Patrick Lauke
 
PDF
Touchevents
guest2f8eaf
 
PDF
The touch events - WebExpo
Peter-Paul Koch
 
PDF
Voices That Matter: JavaScript Events
Peter-Paul Koch
 
PDF
The touch events
Peter-Paul Koch
 
PPTX
Fast multi touch enabled web sites
Aspenware
 
PPT
Flash Lite & Touch: build an iPhone-like dynamic list
Small Screen Design
 
PPTX
Keyboard and mouse events in python
mal6ayer
 
PDF
Getting touchy - an introduction to touch events / Web Standards Days / Mosco...
Patrick Lauke
 
PDF
Developing social simulations with UbikSim
Emilio Serrano
 
PDF
Wii Ruby All Work And No Play Just Wont Do
LittleBIGRuby
 
Getting touchy - an introduction to touch and pointer events (1 day workshop)...
Patrick Lauke
 
Getting touchy - an introduction to touch and pointer events / Smashing Confe...
Patrick Lauke
 
Getting touchy - an introduction to touch and pointer events (complete master...
Patrick Lauke
 
Getting touchy - an introduction to touch and pointer events / Frontend NE / ...
Patrick Lauke
 
Getting touchy - an introduction to touch and pointer events / Workshop / Jav...
Patrick Lauke
 
Getting touchy - an introduction to touch and pointer events (Workshop) / Jav...
Patrick Lauke
 
Getting touchy - an introduction to touch and pointer events / Future of Web ...
Patrick Lauke
 
Getting touchy - an introduction to touch and pointer events / Sainté Mobile ...
Patrick Lauke
 
Touchevents
guest2f8eaf
 
The touch events - WebExpo
Peter-Paul Koch
 
Voices That Matter: JavaScript Events
Peter-Paul Koch
 
The touch events
Peter-Paul Koch
 
Fast multi touch enabled web sites
Aspenware
 
Flash Lite & Touch: build an iPhone-like dynamic list
Small Screen Design
 
Keyboard and mouse events in python
mal6ayer
 
Getting touchy - an introduction to touch events / Web Standards Days / Mosco...
Patrick Lauke
 
Developing social simulations with UbikSim
Emilio Serrano
 
Wii Ruby All Work And No Play Just Wont Do
LittleBIGRuby
 

Similar to Getting touchy - an introduction to touch events / Sainté Mobile Days / Saint-Etienne 22.11.2013 (18)

PPTX
Mobile Web on Touch Event and YUI
Morgan Cheng
 
PDF
The touch events
Peter-Paul Koch
 
PPTX
Tips for building fast multi touch enabled web sites
Aspenware
 
PPTX
Getting Touchy Feely with the Web
Andrew Fisher
 
PDF
T3con10_html5_kosack_zinner
Robert Zinner
 
PPTX
Getting Web Multi-Touch Working
Aidan Wu
 
KEY
Creating Responsive HTML5 Touch Interfaces
Stephen Woods
 
KEY
Getting the-native-feel
fisherwebdev
 
PPTX
Touch me, I Dare You...
Josh Holmes
 
PDF
Ross Boucher: iPhone Touch Events
SanFrancisco JavaScriptMeetup
 
PPTX
Touch the web
Chris Love
 
PPTX
CSS for Touch Devices
Emma Woods
 
PPT
9781305078444 ppt ch10
Terry Yoast
 
PPTX
дыдыкин егор
kuchinskaya
 
PDF
Sperimentazioni lezione6 from_designtoapplication copy
Salvatore Iaconesi
 
PPTX
Ch10 - Programming for Touchscreens and Mobile Devices
dcomfort6819
 
PDF
移动端 Web 开发技术交流
Ximing Dai
 
PDF
Web Apps vs Web Site
Matt Evans
 
Mobile Web on Touch Event and YUI
Morgan Cheng
 
The touch events
Peter-Paul Koch
 
Tips for building fast multi touch enabled web sites
Aspenware
 
Getting Touchy Feely with the Web
Andrew Fisher
 
T3con10_html5_kosack_zinner
Robert Zinner
 
Getting Web Multi-Touch Working
Aidan Wu
 
Creating Responsive HTML5 Touch Interfaces
Stephen Woods
 
Getting the-native-feel
fisherwebdev
 
Touch me, I Dare You...
Josh Holmes
 
Ross Boucher: iPhone Touch Events
SanFrancisco JavaScriptMeetup
 
Touch the web
Chris Love
 
CSS for Touch Devices
Emma Woods
 
9781305078444 ppt ch10
Terry Yoast
 
дыдыкин егор
kuchinskaya
 
Sperimentazioni lezione6 from_designtoapplication copy
Salvatore Iaconesi
 
Ch10 - Programming for Touchscreens and Mobile Devices
dcomfort6819
 
移动端 Web 开发技术交流
Ximing Dai
 
Web Apps vs Web Site
Matt Evans
 
Ad

More from Patrick Lauke (20)

PDF
These (still) aren't the SCs you're looking for ... (mis)adventures in WCAG 2...
Patrick Lauke
 
PDF
Pointer Events Working Group update / TPAC 2023 / Patrick H. Lauke
Patrick Lauke
 
PDF
These aren't the SCs you're looking for ... (mis)adventures in WCAG 2.x inter...
Patrick Lauke
 
PDF
These aren't the SCs you're looking for ... (mis)adventures in WCAG 2.x inter...
Patrick Lauke
 
PDF
Too much accessibility - good intentions, badly implemented / Public Sector F...
Patrick Lauke
 
PDF
Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...
Patrick Lauke
 
PDF
Evaluating web sites for accessibility with Firefox / Manchester Digital Acce...
Patrick Lauke
 
PDF
Managing and educating content editors - experiences and ideas from the trenc...
Patrick Lauke
 
PDF
Implementing Web Standards across the institution: trials and tribulations of...
Patrick Lauke
 
PDF
Geolinking content - experiments in connecting virtual and physical places / ...
Patrick Lauke
 
PDF
All change for WCAG 2.0 - what you need to know about the new accessibility g...
Patrick Lauke
 
PDF
Web Accessibility - an introduction / Salford Business School briefing / Univ...
Patrick Lauke
 
PDF
Doing it in style - creating beautiful sites, the web standards way / WebDD /...
Patrick Lauke
 
PDF
Web standards pragmatism - from validation to the real world / Web Developers...
Patrick Lauke
 
PDF
Ian Lloyd/Patrick H. Lauke: Accessified - practical accessibility fixes any w...
Patrick Lauke
 
PDF
The state of the web - www.salford.ac.uk / 2007
Patrick Lauke
 
PDF
Keyboard accessibility - just because I don't use a mouse doesn't mean I'm se...
Patrick Lauke
 
PDF
WAI-ARIA An introduction to Accessible Rich Internet Applications / JavaScrip...
Patrick Lauke
 
PDF
WAI-ARIA An introduction to Accessible Rich Internet Applications / CSS Minsk...
Patrick Lauke
 
PDF
WAI-ARIA An introduction to Accessible Rich Internet Applications / AccessU 2018
Patrick Lauke
 
These (still) aren't the SCs you're looking for ... (mis)adventures in WCAG 2...
Patrick Lauke
 
Pointer Events Working Group update / TPAC 2023 / Patrick H. Lauke
Patrick Lauke
 
These aren't the SCs you're looking for ... (mis)adventures in WCAG 2.x inter...
Patrick Lauke
 
These aren't the SCs you're looking for ... (mis)adventures in WCAG 2.x inter...
Patrick Lauke
 
Too much accessibility - good intentions, badly implemented / Public Sector F...
Patrick Lauke
 
Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...
Patrick Lauke
 
Evaluating web sites for accessibility with Firefox / Manchester Digital Acce...
Patrick Lauke
 
Managing and educating content editors - experiences and ideas from the trenc...
Patrick Lauke
 
Implementing Web Standards across the institution: trials and tribulations of...
Patrick Lauke
 
Geolinking content - experiments in connecting virtual and physical places / ...
Patrick Lauke
 
All change for WCAG 2.0 - what you need to know about the new accessibility g...
Patrick Lauke
 
Web Accessibility - an introduction / Salford Business School briefing / Univ...
Patrick Lauke
 
Doing it in style - creating beautiful sites, the web standards way / WebDD /...
Patrick Lauke
 
Web standards pragmatism - from validation to the real world / Web Developers...
Patrick Lauke
 
Ian Lloyd/Patrick H. Lauke: Accessified - practical accessibility fixes any w...
Patrick Lauke
 
The state of the web - www.salford.ac.uk / 2007
Patrick Lauke
 
Keyboard accessibility - just because I don't use a mouse doesn't mean I'm se...
Patrick Lauke
 
WAI-ARIA An introduction to Accessible Rich Internet Applications / JavaScrip...
Patrick Lauke
 
WAI-ARIA An introduction to Accessible Rich Internet Applications / CSS Minsk...
Patrick Lauke
 
WAI-ARIA An introduction to Accessible Rich Internet Applications / AccessU 2018
Patrick Lauke
 
Ad

Recently uploaded (20)

PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PPTX
Manual Testing for Accessibility Enhancement
Julia Undeutsch
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
NASA A Researcher’s Guide to International Space Station : Fundamental Physics
Dr. PANKAJ DHUSSA
 
PDF
Modern Decentralized Application Architectures.pdf
Kalema Edgar
 
PPTX
Talbott's brief History of Computers for CollabDays Hamburg 2025
Talbott Crowell
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PDF
Evolution: How True AI is Redefining Safety in Industry 4.0
vikaassingh4433
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Linux schedulers for fun and profit with SchedKit
Alessio Biancalana
 
PPTX
Wondershare Filmora Crack Free Download 2025
josanj305
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Software Development Company Keene Systems, Inc (1).pdf
Custom Software Development Company | Keene Systems, Inc.
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pdf
ghjghvhjgc
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
Manual Testing for Accessibility Enhancement
Julia Undeutsch
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
NASA A Researcher’s Guide to International Space Station : Fundamental Physics
Dr. PANKAJ DHUSSA
 
Modern Decentralized Application Architectures.pdf
Kalema Edgar
 
Talbott's brief History of Computers for CollabDays Hamburg 2025
Talbott Crowell
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
Evolution: How True AI is Redefining Safety in Industry 4.0
vikaassingh4433
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Linux schedulers for fun and profit with SchedKit
Alessio Biancalana
 
Wondershare Filmora Crack Free Download 2025
josanj305
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Software Development Company Keene Systems, Inc (1).pdf
Custom Software Development Company | Keene Systems, Inc.
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pdf
ghjghvhjgc
 

Getting touchy - an introduction to touch events / Sainté Mobile Days / Saint-Etienne 22.11.2013