Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

📱 html5 sensor interaction library for mobile

License

NotificationsYou must be signed in to change notification settings

ehzhang/sense-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

an HTML5 interaction library for mobile browsers

Overview

HTML5 offers a lot of awesome access to hardware data. Sense.js is a library thatabstracts away the math and gives developers and designers easy access to somecommon non-touch gesture interactions with simple javascript callbacks.

Disclaimer

This was made as a part of GreylockU's Hackfest, and will likely see changes to makethings better/add more gestures :)

Pull requests and feature suggestions are welcome!

Demo

You can find a demo athttp://sense-js.jit.su/

Orientation

A ball rolls around based on your screen position!

Flick

Flick your phone to the right or left to slide a color.

Flip

Flip your phone face down and face up, and a new color appears!

Color Fling

Open this page on multiple devices. Selecting a color and flicking it'flicks' that color to all other devices.

Scroll

sense.js enabled scroll based on screen tilt

Quickstart

Download sense.js, and refer to it in an html file, and initialize it!

<scriptsrc="path/to/sense.js"></script><script>varsense=sense.init();sense.flick(function(data){// Your callback code here!});</script>

Documentation

sense.orientation([options], callback)

Orientation fires continuously, and emits alpha, beta, and gamma data from the device.

OptionsDescriptionDefault
alphaThreshold(number) Threshold for changes in delta0
betaThreshold(number) Threshold for changes in beta0
gammaThreshold(number) Threshold for changes in gamma0
radians(boolean) True to emit values in radiansfalse
DataDescription
alpha(number) degree/radian value for direction the device is pointed
beta(number) degree/radian value for device's front-back tilt
gamma(number) degree/radian value for device's left-right tilt

Sample Usage:

sense.orientation(function(data){console.log(data)});

sense.flick([options], callback)

Flick events fire when the device is rotated quickly left-to-right or right-to-left.

OptionsDescriptionDefault
interval(number) the duration in milliseconds to watch for a flick event150
sensitivity(number) multiplier to adjust amount of acceleration required. lower = more sensitive1
DataDescription
direction(String) 'left' or 'right' depending on the flick direction
magnitude(number) the magnitude of the acceleration on flick

Sample Usage:

sense.flick(function(data){slidePage(data.direction)});

sense.fling([options], callback)

Fling events fire when the device is rotated quickly in the front-to-back direction, as ifbeing thrown overhand (with the device facing towards you).

OptionsDescriptionDefault
interval(number) the duration in milliseconds to watch for a flick event150
sensitivity(number) multiplier to adjust amount of acceleration required. lower = more sensitive1
DataDescription
magnitude(number) the magnitude of the acceleration on flick

Sample Usage:

sense.fling(function(data){sendFile();});

sense.flip([options], callback)

Flip events fire when the phone is quickly flipped from face-up to face-down to face-up position.

OptionsDescriptionDefault
gestureDuration(number) timespan in milliseconds that the flip event can occur over150
DataDescription
gamma(number) the final gamma value after the flip

Sample Usage:

sense.flip(function(data){showRandomNumber();});

sense.addTiltScroll([options])

This one line allows the user to observe the tilt of the user's phone to scroll on a page.

OptionsDescriptionDefault
maxHorizontalAngle(number)80
maxHorizontalOffset(number)100
maxHorizontalSpeed(number)15
maxVerticalAngle(number)40
maxVerticalOffset(number)100
maxVerticalSpeed(number)15

Sample Usage:

sense.addTiltScroll();

Debugging

We can initialize Sense with a debug flag!

varsense=sense.init({debug:true});

The debugger will include a fixed div in the bottom right corner that displaysdata when events fire. This is particularly useful when debugging on mobile, as you can'tuse debugger or console.log :(

To start the demo site:

$ npm install$ npm start

[8]ページ先頭

©2009-2025 Movatter.jp