Skip to content

Commit

Permalink
Adjust math to fix motion based animation that moved out of range
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron423698 committed Aug 18, 2011
1 parent 8cd6ed3 commit cd2b019
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions js/plax.js
Expand Up @@ -160,7 +160,7 @@

var x = e.pageX,
y = e.pageY

if(motionEnabled == true){
// portrait(%2==0) or landscape
var i = window.orientation ? (window.orientation +180) %360 / 90 : 2,
Expand All @@ -170,11 +170,18 @@
// facing up(>=2) or down
x = i>=2 ? tmp_x : -tmp_x
y = i>=2 ? tmp_y : -tmp_y

// reset small overages to keep it within range
x = (x > 1 || x < -1) ? Math.round(x) : x
y = (y > 1 || y < -1) ? Math.round(y) : y

// change value from a range of -1 to 1 => 0 to 1
x = (x+1)/2
y = (y+1)/2
}

var strength = (motionEnabled == true && window.orientation) ? 5 : 2,
hRatio = x/((motionEnabled == true) ? strength : docWidth),
vRatio = y/((motionEnabled == true) ? strength : docHeight),
var hRatio = x/((motionEnabled == true) ? 1 : docWidth),
vRatio = y/((motionEnabled == true) ? 1 : docHeight),
layer, i

for (i = layers.length; i--;) {
Expand Down

0 comments on commit cd2b019

Please sign in to comment.