27.03.2017 Views

ng-book

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

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

Mobile Apps 461<br />

Swipe directives example<br />

$swipe Service<br />

For more custom touch-based animations, we can use the $swipe service directly. The $swipe service<br />

is a service that abstracts the details of hold-and-drag swipi<strong>ng</strong> behavior.<br />

The $swipe service has a si<strong>ng</strong>le method called bind(). This bind() method takes an element to<br />

which it binds the swipe actions as well as an object with four event handlers.<br />

These event handlers are called with an object that contains the coordinates object, like so: { x:<br />

200, y: 300 }.<br />

The four events handlers handle the followi<strong>ng</strong> events:<br />

• start<br />

The start event is fired on either a mousedown or a touchstart event. After this event, the $swipe<br />

service sets up watches for touchmove and mousemove events. These events are only fired until the<br />

total distance moved exceeds a small distance (to prevent accidental swipes).<br />

Once this distance has been surpassed, one of two events happens:<br />

• If the vertical delta is greater than the horizontal, the browser takes over as a scroll event.<br />

• If the horizontal delta is greater than the vertical delta, the action is considered a swipe, and<br />

our move and end events are set to follow the swipe.<br />

• move<br />

The move event is called on mousemove and touchmove events only after the $swipe service has<br />

determined that a swipe is, in fact, in progress.<br />

• end

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

Saved successfully!

Ooh no, something went wrong!