25.02.2013 Views

Peter Lubbers - Pro HTML 5 Programming

Pro HTML 5 Programming

Pro HTML 5 Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

264<br />

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

Orientation<br />

The simplest event to handle on a mobile device is the orientation event. The orientation event can be<br />

added to the document body:<br />

<br />

In the event handler for the orientation change, your code can reference the window.orientation<br />

property. This property will give one of the rotation values shown in Table 11-1, which is relative to the<br />

orientation the device was in when the page was initially loaded.<br />

Table 11-1. Orientation Values and Their Meanings<br />

Orientation<br />

Value<br />

Meaning<br />

0 The page is being held in the same orientation as its original load.<br />

-90 The device has been rotated 90 degrees clockwise (right) since the original load.<br />

180 The device has been rotated upside-down since the original page load.<br />

90 The device has been rotated 90 degrees counter-clockwise (left) since the page was<br />

originally loaded.<br />

Once the orientation is known, you can choose to adjust the content accordingly.<br />

Gestures<br />

The next type of event supported by mobile devices is a high-level event known as the gesture. Consider<br />

gesture events as representing a multitouch change in size or rotation. This is usually performed when<br />

the user places two or more fingers on the screen simultaneously and pinches or twists. A twist<br />

represents a rotation, while a pinch in or out represents a zoom out or in, respectively. To receive gesture<br />

events, your code needs to register one of the handlers shown in Table 11-2.<br />

Table 11-2. Event Handlers for Gestures<br />

Event Handler Description<br />

ongesturestart A user has placed multiple fingers on the screen and has begun a movement.<br />

ongesturechange The user is in the process of moving multiple fingers in a scale or rotation.<br />

ongestureend The user has completed the scale or rotation by removing fingers.<br />

x

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

Saved successfully!

Ooh no, something went wrong!