Skip to content

Instantly share code, notes, and snippets.

@liddiard
Last active February 24, 2017 23:08
Show Gist options
  • Save liddiard/83a6514dfd3cbf0a9a9e5180f52e0728 to your computer and use it in GitHub Desktop.
Save liddiard/83a6514dfd3cbf0a9a9e5180f52e0728 to your computer and use it in GitHub Desktop.
Messing around with device orientation API to rotate a webpage with the gyroscope movement, like viewing a Snapchat shot on Spectacles but way less interesting.
(function(){
document.body.style.width = '100vw';
document.documentElement.style.width = '100vw';
document.body.style.height = '100vh';
document.documentElement.style.height = '100vh';
document.body.style.overflow = 'scroll';
document.documentElement.style.overflow = 'scroll';
window.addEventListener("deviceorientation", event => {
if (this.timeoutId) {
window.cancelAnimationFrame(this.timeoutId);
}
this.timeoutId = window.requestAnimationFrame(() => {
document.body.style.transform = `rotate(${event.alpha}deg)`
});
}, true);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment