Browse files

Add new option to set number of degrees tilt needed for full range. W…

…ill give get back some of the functionality that was lost when restricting gyro to same range as desktop by using wider range of tilt, and by setting a larger range of object motion.

Also fixes the options handling in enable() so they aren't set every update, but only once.
  • Loading branch information...
1 parent a8c8ee6 commit 23149235756df254dde885d4fbccab1679a93ad7 @magebarf magebarf committed May 2, 2013
Showing with 9 additions and 5 deletions.
  1. +8 −5 js/plax.js
  2. +1 −0 readme.md
View
13 js/plax.js
@@ -30,6 +30,7 @@
lastRender = new Date().getTime(),
layers = [],
plaxActivityTarget = $(window),
+ motionDegrees = 30,
motionMax = 1,
motionMin = -1,
motionStartX = null,
@@ -167,8 +168,8 @@
values = valuesFromMotion(e)
// Admittedly fuzzy measurements
- x = values.x / 30
- y = values.y / 30
+ x = values.x / motionDegrees
+ y = values.y / motionDegrees
// Ensure not outside of expected range, -1 to 1
x = x < motionMin ? motionMin : (x > motionMax ? motionMax : x)
y = y < motionMin ? motionMin : (y > motionMax ? motionMax : y)
@@ -210,10 +211,12 @@
//
// returns nothing
enable: function(opts){
+ if (opts) {
+ if (opts.activityTarget) plaxActivityTarget = opts.activityTarget || $(window)
+ if (typeof opts.gyroRange === 'number' && opts.gyroRange > 0) motionDegrees = opts.gyroRange
+ }
+
$(document).bind('mousemove.plax', function (e) {
- if(opts){
- plaxActivityTarget = opts.activityTarget || $(window)
- }
plaxifier(e)
})
View
1 readme.md
@@ -87,6 +87,7 @@ __Parameters__
`activityTarget` &mdash; Object: (optional) sets a specific DOM element over which Plax will track the mouse.
+`gyroRange` &mdash; Integer / Float: (optional) sets the degrees of tilt needed to reach full movement in one direction, from the center position. For the full range, two times the degrees tilt is needed. Default value: 30.
### disable()

0 comments on commit 2314923

Please sign in to comment.