1.0.1 • Published 9 years ago

otolith v1.0.1

Weekly downloads
6
License
MIT
Repository
github
Last release
9 years ago

Otolith

Otolith lets you control things by tilting your device.

Usage

To use Otolith, tell it which axis you want to listen to, give it a callback, and watch it go! Otolith only allows rotation on one axis, but there's nothing stopping you setting up more than one.

if (window.DeviceOrientationEvent) {
  otolith = new Otolith({
    axis: 'x',
    callback: function (val) { /* */ }
  );
}

The value passed to the callback is a number in the range -1,1 representing the current point through the rotation.

If you wish, you may stop your callback being called, either temporarily or permanently. You can use the start and stop functions to stop your callback being called.

Options

axis

(required)

The axis you want to watch. Can be 'x', 'y', or 'z'.

callback

(required)

Will be called a lot. Be prepared.

range

(optional)

otolith = new Otolith({
  axis: 'x',
  callback: function (val) { /* */ }
  range: 35
});

This will map the extremes of the value passed to your callback to a smaller range of rotation. For instance, if you pass a range of 35, any degree of rotation greater than 35° will produce a value of 1. This works in the negative direction as well.