mobile web on touch event and yui

51
Mobile Web on Touch Device & YUI Morgan Cheng Jan 25 th 2011

Upload: mocheng

Post on 09-May-2015

3.874 views

Category:

Technology


0 download

DESCRIPTION

Touch device and

TRANSCRIPT

Page 1: Mobile Web on Touch Event and YUI

Mobile Web on Touch Device &

YUI

Morgan Cheng Jan 25th 2011

Page 2: Mobile Web on Touch Event and YUI

Why Mobile?

Page 3: Mobile Web on Touch Event and YUI
Page 4: Mobile Web on Touch Event and YUI

Why Touch Device?

Page 5: Mobile Web on Touch Event and YUI

Touch is Direct User Intent

Page 6: Mobile Web on Touch Event and YUI

Touch Device

Page 7: Mobile Web on Touch Event and YUI

Why Web?

Page 8: Mobile Web on Touch Event and YUI

Web: Cross Platform Solution

Page 9: Mobile Web on Touch Event and YUI

Web: Cross Platform Solution

Page 10: Mobile Web on Touch Event and YUI

Web: Cross Platform Solution

Page 11: Mobile Web on Touch Event and YUI

Mobile + Touch Device + Web

Page 12: Mobile Web on Touch Event and YUI

Touch API Support Layer

Hardware

OS

Browser

Web App

Page 13: Mobile Web on Touch Event and YUI

Apple Touch Layer

Hardware

OS

Browser

Web App

Page 14: Mobile Web on Touch Event and YUI

Microsoft Touch Layer: Limited

Hardware

OS

Browser

Web App

Page 15: Mobile Web on Touch Event and YUI

Android Layer: Not Complete

Hardware

OS

Browser

Web App

Page 16: Mobile Web on Touch Event and YUI

What’s different for Mobile Touch Web?

Page 17: Mobile Web on Touch Event and YUI

Touch Event

Page 18: Mobile Web on Touch Event and YUI

Why not mousedown/mousemove/mouse

up?

Page 19: Mobile Web on Touch Event and YUI

• mousedown/mousemove/mouseup doesn’t work as usual in touch browser

• Semantically, touch event is different from mouse event

• Multi-touch!!!

Page 20: Mobile Web on Touch Event and YUI

How does touch event look?

Page 21: Mobile Web on Touch Event and YUI

Touch Events in iOS/Safari

• touchstart• touchmove• touchend• touchcancel

Page 22: Mobile Web on Touch Event and YUI

Touch Events in iOS/Safari

var target = document.getElementById(‘demo’);target.addEventListener(‘touchstart’, function(e) {

// e.touches// e.targetTouches// e.changedTouches

}, false);

Page 23: Mobile Web on Touch Event and YUI

Touch Events in iOS/Safari

var target = document.getElementById(‘demo’);target.addEventListener(‘touchstart’, function(e) {

// e.touches[0].clientX// e.touches[0].clientY// e.touches[0].screenX// e.touches[0].screenY// e.touches[0].pageX// e.touches[0].pageY

// e.touches[0].target // e.touches[0].identifier}, false);

Page 24: Mobile Web on Touch Event and YUI

Touch Events in Android/Webkit

• No multi-touch till Android 3

• event property– event.touch === event.touches[0]

Page 25: Mobile Web on Touch Event and YUI

Touch Events in Firefox 4 Beta

• MozTouchDown• MozTouchMove• MozTouchUp

Page 26: Mobile Web on Touch Event and YUI

Touch Events in Firefox 4 Beta

document.addEventListener(‘MozTouchDown’, function(e) {// e.clientX

// e.clientY// e.streamId

// e.mozInputType}, false);

Page 27: Mobile Web on Touch Event and YUI

Touch Friendly CSS

Page 28: Mobile Web on Touch Event and YUI

Eliminate :hover pseudo class

Page 29: Mobile Web on Touch Event and YUI

How to tell whether it is a touch device?

Page 30: Mobile Web on Touch Event and YUI

Server Side UserAgent Sniffing

RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$RewriteRule ^(.*)$ http://ipad.domain.com [R=301]

Page 31: Mobile Web on Touch Event and YUI

Media Query

@media handheld, only screen and (max-device-width: 1024px) {

/* iPad specific CSS */}

<link type="text/css" rel="stylesheet" media="only screen and (max-device-width: 480px)"

href="iPhone.css">

Page 32: Mobile Web on Touch Event and YUI

JavaScript Sniffing

function isIPad(){ return navigator.platform == "iPad";}

function isTouchDevice() { return ‘ontouchstart’ in document;}

Page 33: Mobile Web on Touch Event and YUI

Gesture

Page 34: Mobile Web on Touch Event and YUI

Touch Event

Gesture Event

User Action

User Intent

Page 35: Mobile Web on Touch Event and YUI

Gesture Events in iOS/Safari

• gesturestart

• gesturechange

• gestureend

Page 36: Mobile Web on Touch Event and YUI

Gesture: Only for Multi Touch

Page 37: Mobile Web on Touch Event and YUI

Gesture Events in iOS

var target = document.getElementById(‘demo’);target.addEventListener(‘gesturechange’, function(e) {

// e.scale// e.rotation

}, false);

Page 38: Mobile Web on Touch Event and YUI

Gesture Events in Webkit on Android

Not yet

But, Android 3 will have it

Page 39: Mobile Web on Touch Event and YUI

YUI with Touch

Page 40: Mobile Web on Touch Event and YUI

YUI Touch Events is simple wrapper

Page 41: Mobile Web on Touch Event and YUI

Touch Events in YUI

Y.one(“#demo”).on(“touchstart”, function(e) {// e.touches// e.targetTouches// e.changedTouches

// Each element of these arrays are instance of // DOMEventFacade }, false);

Page 42: Mobile Web on Touch Event and YUI

Touch Events in YUI

Y.one(“#demo”).on(“gesturechange”, function(e) {// e.scale// e.rotation

}, false);

Page 43: Mobile Web on Touch Event and YUI

YUI Gesture Events is abstraction of mouse and touch

Page 44: Mobile Web on Touch Event and YUI

Drag & Drop

Page 45: Mobile Web on Touch Event and YUI

D&D

Mouse Event Touch Event

Page 46: Mobile Web on Touch Event and YUI

Extend Touch Event with Synthetic Event

Page 47: Mobile Web on Touch Event and YUI

flick

Page 48: Mobile Web on Touch Event and YUI

gesturemovestartgesturemove

gesturemoveend

Page 49: Mobile Web on Touch Event and YUI

Summary

• Focus User Intent

• Make Touch Friendly UI

• YUI Helps

Page 50: Mobile Web on Touch Event and YUI

Resources

• Touch State-of-the-arthttp://www.quirksmode.org/blog/archives/2010/02/the_touch_actio.html

• Touch and Gesture on iOShttp://www.sitepen.com/blog/2008/07/10/touching-and-gesturing-on-the-iphone/

• Touch on Firefox 4http://hacks.mozilla.org/2010/08/firefox4-beta3/

Page 51: Mobile Web on Touch Event and YUI

ThanksQ&A