SlideShare ist ein Scribd-Unternehmen logo
1 von 50
Downloaden Sie, um offline zu lesen
The touch events
                 Peter-Paul Koch
          http://quirksmode.org
          http://twitter.com/ppk
  <!DOCTYPE html>, 13 April 2011




                                   1
Before we start
• please open the following link on your
  phone

• http://quirksmode.org/touchevents
• It gives links to test files I’ll refer to in my
  presentation.
• The touch tests work on iPhone, Android,
  bada, BlackBerry Torch, and Opera Mobile
  10.1+

                                                    2
In the beginning
was the mouse




                   3
In the beginning Then we figured out
was the mouse we had to do
                 something about the
                 keyboard, too.



                                       4
Text
And now we also have touch




                             5
Interaction modes
• They sometimes need different approaches
• but at other times a similar approach
• It’s all a matter of events




                                             6
keydown
keypress
keyup



           7
mouseover
mouseout
mousedown
mouseup
mousemove
mouseenter
mouseleave




             8
touchstart
touchmove
touchend
touchcancel




              9
Interaction modes
• On desktop it’s simple
• Someone uses either the keyboard, or the
  mouse
• The two interaction modes can largely
  ignore each other
• (though they may use the same functions)
• On mobile it’s not so simple
                                             10
Interaction modes
• Nokia E71
• No touchscreen




                       11
Interaction modes
• Nokia E71
• No touchscreen
• 4-way navigation (keys)




                            12
Interaction modes
• Nokia E71
• No touchscreen
• 4-way navigation (keys)
• but the keys steer a
  mouse cursor
• Key events and mouse
  events at the same time


                            13
Besides, touchscreen phones must
support the mouse events, too.

There are too many websites that depend
on mouse events.




                                          14
Example 1
• http://quirksmode.org/touchevents
• Open the first dropdown example
• Task: Click on option 3.2
• Works. A bit oddly, but works.
• This script uses mouseover and mouseout;
  no touch events.



                                             15
Example 2
• http://quirksmode.org/touchevents
• Now open the second dropdown example
• Task: Click on option 3.2
• Does not work.
• This is with the touch events swapped in
  for the mouse events.



                                             16
Comparison
• Not a fair comparison.
• Touchstart and touchend are not the
  equivalents of mouseover and mouseout.
• Mouseover and mouseout are about hover
  state
• and hover state does not exist on
  touchscreens.


                                           17
Hover
• Hover states cannot function on
  touchscreens.
• There is no way of saying “I may be
  interested in this element, but I’m not sure
  yet.”
• This will change the ways we interact with
  websites
• change for the good
                                                 18
Interaction modes
Mouse         Keyboard Touch
mousedown     keydown        touchstart
mousemove     keypress       touchmove
mouseup       keyup          touchend
mouseover     focus          -
mouseout      blur           -
load, unload, click, submit, resize,
zoom, change etc. etc.
                                          19
Interaction modes
Mouse         Keyboard Touch
mousedown     keydown        touchstart
mousemove     keypress       touchmove
mouseup       keyup          touchend
mouseover     focus          -
mouseout      blur           -
load, unload, click, submit, resize,
zoom, change etc. etc.
                                          20
Interaction modes
Mouse         Keyboard Touch
mousedown     keydown        touchstart
mousemove     keypress       touchmove
mouseup       keyup          touchend
mouseover     focus          -
mouseout      blur           -
load, unload, click, submit, resize,
zoom, change etc. etc.
                                          21
Interaction modes
Mouse         Keyboard Touch
mousedown     keydown        touchstart
mousemove     keypress       touchmove
mouseup       keyup          touchend
mouseover     focus          -
mouseout      blur           -
load, unload, click, submit, resize,
zoom, change etc. etc.
                                          22
Stick with
       click
• Really means “activate”
• Works everywhere, on every phone
• But: slow                          23
The slowness of click
If you touch an element, it may mean several
things
• “I want to single-tap”
• “I want to scroll this”
• “I want to pinch-zoom”
• “I want to double-tap”
Thus a click (or rather, a single tap) is a bit
slow: it needs to wait until the OS is certain
you don’t want to do anything else.

                                                  24
The touch event spec

• Touchstart, touchmove, touchend
• touches, changedTouches, target Touches
• Touchenter, touchleave
• Area
• Force


                                            25
Touch and mouse
• If you touch an element the touch events
  fire,
• but the mouse events fire, too.
• Just not quite like you’re used to




                                             26
Touch and mouse
If you touch an element, the following events all
fire, in this order:
• touchstart
• mouseover
• mousemove (only one!)
• mousedown
• mouseup
• click
• :hover styles are applied
                                                    27
Touch and mouse
That’s not as big a problem as you’d think.

Generally you use either the touch events
or just one mouse event.

Only problem: mousemove. But it won’t work on
touchscreens in any case.




                                                28
Touchmove
• Touchmove fires when the touch moves
  (<duh />)
• But...
• it continues firing even if the finger leaves
  the element the event is handled on.
• element.ontouchmove       = doSomething;
• doSomething is still called after the finger
  leaves the element
• What we’d really need is touchenter and
  touchleave. They’re in the spec, but not yet
  supported.
                                                 29
Touch and mouse
• touchstart
• mouseover
• mousemove (only one!)
• mousedown
• mouseup
• click
• :hover styles are applied


                              30
Touch and mouse
• touchstart
• mouseover
• mousemove (only one!)
On iPhone and Symbian,
if a DOM change occurs onmouseover or
onmousemove,
all other events are cancelled.
This probably makes sense
somehow...

                                        31
Touch and mouse
If you touch another element,

• the mouseout event fires on the original
  element
• the :hover styles are removed from the
  original element
• Now you understand why the first
  dropdown menu works as it works.



                                            32
Example 3
• http://quirksmode.org/touchevents
• See for yourself at the touch action test
  page.

• (This is the page I used to determine all
  these facts.)




                                              33
Example 4
• http://quirksmode.org/touchevents
• Now try the Event Delegation page.
• I created it to study the weirdest bug ever.
  On the iPhone.




                                                 34
iPhone bug
• If you touch the bordered div a click event
  fires (eventually)
• It’s supposed to bubble up to the
  document, where it is caught
• document.onclick       = changeBorder;
• However, on the iPhone the bubbling stops
  just below the <body>.
• For the life of me I can’t figure out why
  (though it’s likely deliberate)

                                                35
iPhone bug
• Workaround:
• make sure that the div is clickable:
• div.onclick = function (){}
• An empty event handler is enough.
• Or ...
• div   {cursor: pointer}
• Don’t ask me why Apple thought this was a
  good idea.

                                              36
Example 5
• http://quirksmode.org/touchevents
• The first drag-and-drop example
• Works fine with mouse or touch.
• mousedown-mousemove-mouseup
• touchstart-touchmove-touchend
• Completely equivalent

                                      37
So mousedown and mouseup are the true
equivalents of touchstart and touchend.

Still, that doesn’t mean they’re the same.




                                             38
Touch !== mouse
• Area
• Pressure
• Temperature
• Multitouch




                      39
Drag and drop
element.onmousedown = function (e) {
! // initialise
! document.onmousemove = function (e) {
! ! // move
! }
! document.onmouseup = function (e) {
! ! document.onmousemove = null;
! ! document.onmouseup = null;
! }
}

                                          40
Drag and drop
element.onmousedown = function (e) {
! // initialise
! document.onmousemove = function (e) {
! ! // move
! }
! document.onmouseup = function (e) {
! ! document.onmousemove = null;
! ! document.onmouseup = null;
! }
}

                                          41
Drag and drop
element.onmousedown = function (e) {
! // initialise
! document.onmousemove = function (e) {
! ! // move
! }
! document.onmouseup = function (e) {
! ! document.onmousemove = null;
! ! document.onmouseup = null;
! }
}

                                          42
Drag and drop
element.onmousedown = function (e) {
! // initialise
! document.onmousemove = function (e) {
! ! // move
! }
! document.onmouseup = function (e) {
! ! document.onmousemove = null;
! ! document.onmouseup = null;
! }
}

                                          43
Drag and drop
element.ontouchstart = function (e) {
! // initialise
! document.ontouchmove = function (e) {
! ! // move
! }
! document.ontouchend = function (e) {
! ! document.ontouchmove = null;
! ! document.ontouchend = null;
! }
}

                                          44
Drag and drop
element.ontouchstart = function (e) {
! // initialise
! element.ontouchmove = function (e) {
! ! // move
! }
! element.ontouchend = function (e) {
! ! element.ontouchmove = null;
! ! element.ontouchend = null;
! }
}

                                         45
Drag and drop
// for mouse
element.onmousedown = function (e) {
  // yaddah
}

// for touch
element.ontouchstart = function (e) {
  // yaddah

}

                                        46
Drag and drop
// for mouse
element.onmousedown = function (e) {
  // yaddah
}

// for touch
element.ontouchstart = function (e) {
  // yaddah
  element.onmousedown = null;
}

                                        47
Example 6
• http://quirksmode.org/touchevents
• The second drag-and-drop example
• Multitouch, baby!
• Works only on iPhone and (a bit stilted)
  Opera Mobile 10.1+
• Completely impossible with mouse
• Would be fun for games, especially on a
  tablet

                                             48
Example 7
• http://quirksmode.org/touchevents
• The scrolling layer example
• Works fine in all browsers that support the
  touch events
• But: how are we going to port this to other
  interaction models?
• Keyboard: arrow keys
• But what about the mouse?
                                                49
Thank you!
           Questions?
http://quirksmode.org
http://twitter.com/ppk

I'll post these slides on my site.

                                     50

Weitere ähnliche Inhalte

Ähnlich wie The touch events

The touch events - WebExpo
The touch events - WebExpoThe touch events - WebExpo
The touch events - WebExpoPeter-Paul Koch
 
DHTML - Events & Buttons
DHTML - Events  & ButtonsDHTML - Events  & Buttons
DHTML - Events & ButtonsDeep Patel
 
T3con10_html5_kosack_zinner
T3con10_html5_kosack_zinnerT3con10_html5_kosack_zinner
T3con10_html5_kosack_zinnerRobert Zinner
 
Common Keyboard and Mouse Problems
Common Keyboard and Mouse ProblemsCommon Keyboard and Mouse Problems
Common Keyboard and Mouse ProblemsCarlo Caharian
 
Getting touchy - an introduction to touch and pointer events (1 day workshop)...
Getting touchy - an introduction to touch and pointer events (1 day workshop)...Getting touchy - an introduction to touch and pointer events (1 day workshop)...
Getting touchy - an introduction to touch and pointer events (1 day workshop)...Patrick Lauke
 
Getting touchy - an introduction to touch and pointer events / Frontend NE / ...
Getting touchy - an introduction to touch and pointer events / Frontend NE / ...Getting touchy - an introduction to touch and pointer events / Frontend NE / ...
Getting touchy - an introduction to touch and pointer events / Frontend NE / ...Patrick Lauke
 
Scratch Introduction
Scratch IntroductionScratch Introduction
Scratch IntroductionGirijaSuthoju
 
Simple Expressions At Play
Simple Expressions At PlaySimple Expressions At Play
Simple Expressions At PlayShashank Tiwari
 
grade seven presentation topic: computer Mousepptx
grade seven presentation topic: computer Mousepptxgrade seven presentation topic: computer Mousepptx
grade seven presentation topic: computer Mousepptxvirginiarueda4
 
Understanding the Touch Interface [IndicThreads Mobile Application Developmen...
Understanding the Touch Interface [IndicThreads Mobile Application Developmen...Understanding the Touch Interface [IndicThreads Mobile Application Developmen...
Understanding the Touch Interface [IndicThreads Mobile Application Developmen...IndicThreads
 
CSS for Touch Devices
CSS for Touch DevicesCSS for Touch Devices
CSS for Touch DevicesEmma Woods
 
The Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event HandlingThe Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event HandlingYorick Phoenix
 

Ähnlich wie The touch events (20)

The touch events
The touch eventsThe touch events
The touch events
 
The touch events - WebExpo
The touch events - WebExpoThe touch events - WebExpo
The touch events - WebExpo
 
Using the Mouse
Using the MouseUsing the Mouse
Using the Mouse
 
DHTML - Events & Buttons
DHTML - Events  & ButtonsDHTML - Events  & Buttons
DHTML - Events & Buttons
 
mouse-201203131835.pdf
mouse-201203131835.pdfmouse-201203131835.pdf
mouse-201203131835.pdf
 
mouse-201203131835.pdf
mouse-201203131835.pdfmouse-201203131835.pdf
mouse-201203131835.pdf
 
Computer Mouse
 Computer Mouse Computer Mouse
Computer Mouse
 
T3con10_html5_kosack_zinner
T3con10_html5_kosack_zinnerT3con10_html5_kosack_zinner
T3con10_html5_kosack_zinner
 
Common Keyboard and Mouse Problems
Common Keyboard and Mouse ProblemsCommon Keyboard and Mouse Problems
Common Keyboard and Mouse Problems
 
How do i
How do iHow do i
How do i
 
Getting touchy - an introduction to touch and pointer events (1 day workshop)...
Getting touchy - an introduction to touch and pointer events (1 day workshop)...Getting touchy - an introduction to touch and pointer events (1 day workshop)...
Getting touchy - an introduction to touch and pointer events (1 day workshop)...
 
Getting touchy - an introduction to touch and pointer events / Frontend NE / ...
Getting touchy - an introduction to touch and pointer events / Frontend NE / ...Getting touchy - an introduction to touch and pointer events / Frontend NE / ...
Getting touchy - an introduction to touch and pointer events / Frontend NE / ...
 
Mouse re-programmed
Mouse   re-programmedMouse   re-programmed
Mouse re-programmed
 
The mouse
The mouseThe mouse
The mouse
 
Scratch Introduction
Scratch IntroductionScratch Introduction
Scratch Introduction
 
Simple Expressions At Play
Simple Expressions At PlaySimple Expressions At Play
Simple Expressions At Play
 
grade seven presentation topic: computer Mousepptx
grade seven presentation topic: computer Mousepptxgrade seven presentation topic: computer Mousepptx
grade seven presentation topic: computer Mousepptx
 
Understanding the Touch Interface [IndicThreads Mobile Application Developmen...
Understanding the Touch Interface [IndicThreads Mobile Application Developmen...Understanding the Touch Interface [IndicThreads Mobile Application Developmen...
Understanding the Touch Interface [IndicThreads Mobile Application Developmen...
 
CSS for Touch Devices
CSS for Touch DevicesCSS for Touch Devices
CSS for Touch Devices
 
The Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event HandlingThe Fine Art of JavaScript Event Handling
The Fine Art of JavaScript Event Handling
 

Mehr von Peter-Paul Koch

Rethinking the mobile web
Rethinking the mobile webRethinking the mobile web
Rethinking the mobile webPeter-Paul Koch
 
The mobile browser world
The mobile browser worldThe mobile browser world
The mobile browser worldPeter-Paul Koch
 
The future of the mobile web
The future of the mobile webThe future of the mobile web
The future of the mobile webPeter-Paul Koch
 
The mobile browser world
The mobile browser worldThe mobile browser world
The mobile browser worldPeter-Paul Koch
 
The Mobile Web - Fronteers 2009
The Mobile Web - Fronteers 2009The Mobile Web - Fronteers 2009
The Mobile Web - Fronteers 2009Peter-Paul Koch
 
State of the Mobile Browsers
State of the Mobile BrowsersState of the Mobile Browsers
State of the Mobile BrowsersPeter-Paul Koch
 
Voices That Matter: JavaScript Events
Voices That Matter: JavaScript EventsVoices That Matter: JavaScript Events
Voices That Matter: JavaScript EventsPeter-Paul Koch
 
The Ajax Experience: State Of The Browsers
The Ajax Experience: State Of The BrowsersThe Ajax Experience: State Of The Browsers
The Ajax Experience: State Of The BrowsersPeter-Paul Koch
 
An Event Apart Boston: Principles of Unobtrusive JavaScript
An Event Apart Boston: Principles of Unobtrusive JavaScriptAn Event Apart Boston: Principles of Unobtrusive JavaScript
An Event Apart Boston: Principles of Unobtrusive JavaScriptPeter-Paul Koch
 
Google presentation: The Open Web goes mobile
Google presentation: The Open Web goes mobileGoogle presentation: The Open Web goes mobile
Google presentation: The Open Web goes mobilePeter-Paul Koch
 
Yahoo presentation: JavaScript Events
Yahoo presentation: JavaScript EventsYahoo presentation: JavaScript Events
Yahoo presentation: JavaScript EventsPeter-Paul Koch
 

Mehr von Peter-Paul Koch (14)

Rethinking the mobile web
Rethinking the mobile webRethinking the mobile web
Rethinking the mobile web
 
The mobile browser world
The mobile browser worldThe mobile browser world
The mobile browser world
 
The future of the mobile web
The future of the mobile webThe future of the mobile web
The future of the mobile web
 
The mobile browser world
The mobile browser worldThe mobile browser world
The mobile browser world
 
JSON over SMS
JSON over SMSJSON over SMS
JSON over SMS
 
Samsung
SamsungSamsung
Samsung
 
The Mobile Web - Fronteers 2009
The Mobile Web - Fronteers 2009The Mobile Web - Fronteers 2009
The Mobile Web - Fronteers 2009
 
State of the Mobile Browsers
State of the Mobile BrowsersState of the Mobile Browsers
State of the Mobile Browsers
 
Vodafone Widget Camp
Vodafone Widget CampVodafone Widget Camp
Vodafone Widget Camp
 
Voices That Matter: JavaScript Events
Voices That Matter: JavaScript EventsVoices That Matter: JavaScript Events
Voices That Matter: JavaScript Events
 
The Ajax Experience: State Of The Browsers
The Ajax Experience: State Of The BrowsersThe Ajax Experience: State Of The Browsers
The Ajax Experience: State Of The Browsers
 
An Event Apart Boston: Principles of Unobtrusive JavaScript
An Event Apart Boston: Principles of Unobtrusive JavaScriptAn Event Apart Boston: Principles of Unobtrusive JavaScript
An Event Apart Boston: Principles of Unobtrusive JavaScript
 
Google presentation: The Open Web goes mobile
Google presentation: The Open Web goes mobileGoogle presentation: The Open Web goes mobile
Google presentation: The Open Web goes mobile
 
Yahoo presentation: JavaScript Events
Yahoo presentation: JavaScript EventsYahoo presentation: JavaScript Events
Yahoo presentation: JavaScript Events
 

Kürzlich hochgeladen

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 

Kürzlich hochgeladen (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 

The touch events

  • 1. The touch events Peter-Paul Koch http://quirksmode.org http://twitter.com/ppk <!DOCTYPE html>, 13 April 2011 1
  • 2. Before we start • please open the following link on your phone • http://quirksmode.org/touchevents • It gives links to test files I’ll refer to in my presentation. • The touch tests work on iPhone, Android, bada, BlackBerry Torch, and Opera Mobile 10.1+ 2
  • 3. In the beginning was the mouse 3
  • 4. In the beginning Then we figured out was the mouse we had to do something about the keyboard, too. 4
  • 5. Text And now we also have touch 5
  • 6. Interaction modes • They sometimes need different approaches • but at other times a similar approach • It’s all a matter of events 6
  • 10. Interaction modes • On desktop it’s simple • Someone uses either the keyboard, or the mouse • The two interaction modes can largely ignore each other • (though they may use the same functions) • On mobile it’s not so simple 10
  • 11. Interaction modes • Nokia E71 • No touchscreen 11
  • 12. Interaction modes • Nokia E71 • No touchscreen • 4-way navigation (keys) 12
  • 13. Interaction modes • Nokia E71 • No touchscreen • 4-way navigation (keys) • but the keys steer a mouse cursor • Key events and mouse events at the same time 13
  • 14. Besides, touchscreen phones must support the mouse events, too. There are too many websites that depend on mouse events. 14
  • 15. Example 1 • http://quirksmode.org/touchevents • Open the first dropdown example • Task: Click on option 3.2 • Works. A bit oddly, but works. • This script uses mouseover and mouseout; no touch events. 15
  • 16. Example 2 • http://quirksmode.org/touchevents • Now open the second dropdown example • Task: Click on option 3.2 • Does not work. • This is with the touch events swapped in for the mouse events. 16
  • 17. Comparison • Not a fair comparison. • Touchstart and touchend are not the equivalents of mouseover and mouseout. • Mouseover and mouseout are about hover state • and hover state does not exist on touchscreens. 17
  • 18. Hover • Hover states cannot function on touchscreens. • There is no way of saying “I may be interested in this element, but I’m not sure yet.” • This will change the ways we interact with websites • change for the good 18
  • 19. Interaction modes Mouse Keyboard Touch mousedown keydown touchstart mousemove keypress touchmove mouseup keyup touchend mouseover focus - mouseout blur - load, unload, click, submit, resize, zoom, change etc. etc. 19
  • 20. Interaction modes Mouse Keyboard Touch mousedown keydown touchstart mousemove keypress touchmove mouseup keyup touchend mouseover focus - mouseout blur - load, unload, click, submit, resize, zoom, change etc. etc. 20
  • 21. Interaction modes Mouse Keyboard Touch mousedown keydown touchstart mousemove keypress touchmove mouseup keyup touchend mouseover focus - mouseout blur - load, unload, click, submit, resize, zoom, change etc. etc. 21
  • 22. Interaction modes Mouse Keyboard Touch mousedown keydown touchstart mousemove keypress touchmove mouseup keyup touchend mouseover focus - mouseout blur - load, unload, click, submit, resize, zoom, change etc. etc. 22
  • 23. Stick with click • Really means “activate” • Works everywhere, on every phone • But: slow 23
  • 24. The slowness of click If you touch an element, it may mean several things • “I want to single-tap” • “I want to scroll this” • “I want to pinch-zoom” • “I want to double-tap” Thus a click (or rather, a single tap) is a bit slow: it needs to wait until the OS is certain you don’t want to do anything else. 24
  • 25. The touch event spec • Touchstart, touchmove, touchend • touches, changedTouches, target Touches • Touchenter, touchleave • Area • Force 25
  • 26. Touch and mouse • If you touch an element the touch events fire, • but the mouse events fire, too. • Just not quite like you’re used to 26
  • 27. Touch and mouse If you touch an element, the following events all fire, in this order: • touchstart • mouseover • mousemove (only one!) • mousedown • mouseup • click • :hover styles are applied 27
  • 28. Touch and mouse That’s not as big a problem as you’d think. Generally you use either the touch events or just one mouse event. Only problem: mousemove. But it won’t work on touchscreens in any case. 28
  • 29. Touchmove • Touchmove fires when the touch moves (<duh />) • But... • it continues firing even if the finger leaves the element the event is handled on. • element.ontouchmove = doSomething; • doSomething is still called after the finger leaves the element • What we’d really need is touchenter and touchleave. They’re in the spec, but not yet supported. 29
  • 30. Touch and mouse • touchstart • mouseover • mousemove (only one!) • mousedown • mouseup • click • :hover styles are applied 30
  • 31. Touch and mouse • touchstart • mouseover • mousemove (only one!) On iPhone and Symbian, if a DOM change occurs onmouseover or onmousemove, all other events are cancelled. This probably makes sense somehow... 31
  • 32. Touch and mouse If you touch another element, • the mouseout event fires on the original element • the :hover styles are removed from the original element • Now you understand why the first dropdown menu works as it works. 32
  • 33. Example 3 • http://quirksmode.org/touchevents • See for yourself at the touch action test page. • (This is the page I used to determine all these facts.) 33
  • 34. Example 4 • http://quirksmode.org/touchevents • Now try the Event Delegation page. • I created it to study the weirdest bug ever. On the iPhone. 34
  • 35. iPhone bug • If you touch the bordered div a click event fires (eventually) • It’s supposed to bubble up to the document, where it is caught • document.onclick = changeBorder; • However, on the iPhone the bubbling stops just below the <body>. • For the life of me I can’t figure out why (though it’s likely deliberate) 35
  • 36. iPhone bug • Workaround: • make sure that the div is clickable: • div.onclick = function (){} • An empty event handler is enough. • Or ... • div {cursor: pointer} • Don’t ask me why Apple thought this was a good idea. 36
  • 37. Example 5 • http://quirksmode.org/touchevents • The first drag-and-drop example • Works fine with mouse or touch. • mousedown-mousemove-mouseup • touchstart-touchmove-touchend • Completely equivalent 37
  • 38. So mousedown and mouseup are the true equivalents of touchstart and touchend. Still, that doesn’t mean they’re the same. 38
  • 39. Touch !== mouse • Area • Pressure • Temperature • Multitouch 39
  • 40. Drag and drop element.onmousedown = function (e) { ! // initialise ! document.onmousemove = function (e) { ! ! // move ! } ! document.onmouseup = function (e) { ! ! document.onmousemove = null; ! ! document.onmouseup = null; ! } } 40
  • 41. Drag and drop element.onmousedown = function (e) { ! // initialise ! document.onmousemove = function (e) { ! ! // move ! } ! document.onmouseup = function (e) { ! ! document.onmousemove = null; ! ! document.onmouseup = null; ! } } 41
  • 42. Drag and drop element.onmousedown = function (e) { ! // initialise ! document.onmousemove = function (e) { ! ! // move ! } ! document.onmouseup = function (e) { ! ! document.onmousemove = null; ! ! document.onmouseup = null; ! } } 42
  • 43. Drag and drop element.onmousedown = function (e) { ! // initialise ! document.onmousemove = function (e) { ! ! // move ! } ! document.onmouseup = function (e) { ! ! document.onmousemove = null; ! ! document.onmouseup = null; ! } } 43
  • 44. Drag and drop element.ontouchstart = function (e) { ! // initialise ! document.ontouchmove = function (e) { ! ! // move ! } ! document.ontouchend = function (e) { ! ! document.ontouchmove = null; ! ! document.ontouchend = null; ! } } 44
  • 45. Drag and drop element.ontouchstart = function (e) { ! // initialise ! element.ontouchmove = function (e) { ! ! // move ! } ! element.ontouchend = function (e) { ! ! element.ontouchmove = null; ! ! element.ontouchend = null; ! } } 45
  • 46. Drag and drop // for mouse element.onmousedown = function (e) { // yaddah } // for touch element.ontouchstart = function (e) { // yaddah } 46
  • 47. Drag and drop // for mouse element.onmousedown = function (e) { // yaddah } // for touch element.ontouchstart = function (e) { // yaddah element.onmousedown = null; } 47
  • 48. Example 6 • http://quirksmode.org/touchevents • The second drag-and-drop example • Multitouch, baby! • Works only on iPhone and (a bit stilted) Opera Mobile 10.1+ • Completely impossible with mouse • Would be fun for games, especially on a tablet 48
  • 49. Example 7 • http://quirksmode.org/touchevents • The scrolling layer example • Works fine in all browsers that support the touch events • But: how are we going to port this to other interaction models? • Keyboard: arrow keys • But what about the mouse? 49
  • 50. Thank you! Questions? http://quirksmode.org http://twitter.com/ppk I'll post these slides on my site. 50