25.02.2013 Views

Peter Lubbers - Pro HTML 5 Programming

Pro HTML 5 Programming

Pro HTML 5 Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 11 ■ THE FUTURE OF <strong>HTML</strong>5<br />

During the gesture, the event handler is free to check the rotation and scale properties of the<br />

corresponding event and update the display accordingly. Listing 11-1 shows an example usage of the<br />

gesture handlers.<br />

Listing 11-1. Example Gesture Handler<br />

function gestureChange(event) {<br />

// Retrieve the amount of change in scale caused by the user gesture<br />

// Consider a value of 1.0 to represent the original size, while smaller<br />

// numbers represent a zoom in and larger numbers represent a zoom<br />

// out, based on the ratio of the scale value<br />

var scale = event.scale;<br />

// Retrieve the amount of change in rotation caused by the user gesture<br />

// The rotation value is in degrees from 0 to 360, where positive values<br />

// indicate a rotation clockwise and negative values indicate a counter-<br />

// clockwise rotation<br />

var rotation = event.rotation;<br />

// Update the display based on the rotation.<br />

}<br />

// register our gesture change listener on a document node<br />

node.addEventListener("gesturechange", gestureChange, false);<br />

Gesture events are particularly appropriate in applications that need to manipulate objects or<br />

displays, such as in diagramming tools or navigation tools.<br />

Touches<br />

For those cases where you need low-level control over device events, the touch events provide as much<br />

information as you will likely need. Table 11-3 shows the different touch events.<br />

Table 11-3. Touch Events<br />

Event Handler Description<br />

ontouchstart A finger has been placed on the surface of the touch device. Multitouch events will<br />

occur as more fingers are placed on the device.<br />

ontouchmove One or more of the fingers on the device has moved its location in a drag operation.<br />

ontouchend One or more fingers have been lifted away from the device screen.<br />

ontouchcancel An unexpected interruption has stopped the touch operations.<br />

265

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!