Skip to content

Instantly share code, notes, and snippets.

@june29
Created June 7, 2010 08:46
Show Gist options
  • Save june29/428393 to your computer and use it in GitHub Desktop.
Save june29/428393 to your computer and use it in GitHub Desktop.
傾きに合わせて画像を回転する
// ==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