Last active
July 21, 2016 08:18
-
-
Save vincentorback/50a2a15ce0bcc225d4baeb22cbba3cac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var orientationEls = doc.querySelectorAll('.js-orientation'); | |
window.addEventListener('deviceorientation', function(eventData) { | |
var yTilt = Math.round((-eventData.beta + 90) * (40/180) - 40); | |
var xTilt = Math.round(-eventData.gamma * (20/180) - 20); | |
if (xTilt > 0) { | |
xTilt = -xTilt; | |
} else if (xTilt < -40) { | |
xTilt = -(xTilt + 80); | |
} | |
Array.from(orientationEls, function (el) { | |
window.requestAnimFrame(function () { | |
el.style.transform = 'translate(' + xTilt + 'px, ' + yTilt + 'px)'; | |
}); | |
}); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment