Skip to content

Instantly share code, notes, and snippets.

@vincentorback
Last active July 21, 2016 08:18
Show Gist options
  • Save vincentorback/50a2a15ce0bcc225d4baeb22cbba3cac to your computer and use it in GitHub Desktop.
Save vincentorback/50a2a15ce0bcc225d4baeb22cbba3cac to your computer and use it in GitHub Desktop.
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