Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!doctype html>
<html lang="en">
<head>
  <title>Orientation API and the HTML5 logo</title>
</head>
<body>
  <h2>Device Orientation with HTML5</h2>
  You need to be on a mobile device or use a laptop with accelerometer/orientation device.<p>
  <img src="https://mainline.i3s.unice.fr/mooc/HTML5_Badge_256.png" id="imgLogo" class="logo">
 
<script type="text/javascript">
if (window.DeviceOrientationEvent) {
  console.log("DeviceOrientation is supported");
  window.addEventListener('deviceorientation', function(eventData) {
        var LR = eventData.gamma;
        var FB = eventData.beta;
        var DIR = eventData.alpha;
        deviceOrientationHandler(LR, FB, DIR);
    }, false);
} else {
    alert("Not supported on your device or browser.  Sorry.");
}
 
function deviceOrientationHandler(LR, FB, DIR) {
   //for webkit browser
   document.getElementById("imgLogo").style.webkitTransform = "rotate("+ LR +"deg) rotate3d(1,0,0, "+ (FB*-1)+"deg)";
 
   //for HTML5 standard-compliance
   document.getElementById("imgLogo").style.transform = "rotate("+ LR +"deg) rotate3d(1,0,0, "+ (FB*-1)+"deg)";
}
</script>
 
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers