Last active
February 24, 2017 23:08
-
-
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.
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
(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