Created
June 7, 2010 08:46
-
-
Save june29/428393 to your computer and use it in GitHub Desktop.
傾きに合わせて画像を回転する
This file contains 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
// ==UserScript== | |
// @name Rotate Images | |
// @namespace http://june29.jp/ | |
// @include * | |
// ==/UserScript== | |
(function() { | |
var style = document.createElement('style'); | |
document.body.appendChild(style); | |
style.textContent = "img, canvas, video, object {\n" + "-moz-transform: rotate(0deg);\n" + " }"; | |
var offset = {}; | |
window.addEventListener("MozOrientation", function(data) { | |
if (!offset.x) offset.x = data.x; | |
if (!offset.y) offset.y = data.y; | |
if (!offset.z) offset.z = data.z; | |
var radian = -1 * (data.x - offset.x) * 90; | |
style.sheet.cssRules[0].style.MozTransform = 'rotate(' + radian + 'deg)'; | |
}, true); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment