Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.75 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <title></title>
  6.  
  7.   <style type="text/css">
  8.     body {
  9.       font-family: sans-serif;
  10.     }
  11.  
  12.       .main {
  13.       border: 1px solid black;
  14.       box-shadow: 10px 10px 5px #888;
  15.       border-radius: 12px;
  16.       padding: 20px;
  17.       background-color: #ddd;
  18.       margin: 25px;
  19.       width: 450px;
  20.       margin-left:auto;
  21.       margin-right:auto;  
  22.     }
  23.    
  24.     .logo {
  25.       width:275px;
  26.       margin-left: auto;
  27.       margin-right: auto;
  28.       display: block;
  29.       padding: 15px;
  30.     }
  31.    
  32.     .container {
  33.       -webkit-perspective: 300; perspective: 300;
  34.     }
  35.   </style>
  36.  
  37. </head>
  38. <body>
  39.   <div class="main">
  40.       <h2>Device Orientation</h2>
  41.       <table>
  42.         <tr>
  43.           <td>Event Supported</td>
  44.           <td id="doEvent"></td>
  45.         </tr>
  46.         <tr>
  47.           <td>Tilt Left/Right [gamma]</td>
  48.           <td id="doTiltLR"></td>
  49.         </tr>
  50.         <tr>
  51.           <td>Tilt Front/Back [beta]</td>
  52.           <td id="doTiltFB"></td>
  53.         </tr>
  54.         <tr>
  55.           <td>Direction [alpha]</td>
  56.           <td id="doDirection"></td>
  57.         </tr>
  58.         <tr>
  59.           <td>Acceleration</td>
  60.           <td id="acceleration"></td>
  61.         </tr>
  62.       </table>
  63.   </div>
  64.  
  65.   <div class="container" style="-webkit-perspective: 300; perspective: 300;">
  66.     <img src="html5_logo.png" id="imgLogo" class="logo">
  67.   </div>
  68.  
  69.   <script type="text/javascript">
  70.     init();
  71.     var count = 0;
  72.    
  73.     function init() {
  74.       if (window.DeviceOrientationEvent) {
  75.         document.getElementById("doEvent").innerHTML = "DeviceOrientation";
  76.         // Listen for the deviceorientation event and handle the raw data
  77.         window.addEventListener('deviceorientation', function(eventData) {
  78.           // gamma is the left-to-right tilt in degrees, where right is positive
  79.           var tiltLR = eventData.gamma;
  80.          
  81.           // beta is the front-to-back tilt in degrees, where front is positive
  82.           var tiltFB = eventData.beta;
  83.          
  84.           // alpha is the compass direction the device is facing in degrees
  85.           var dir = eventData.alpha
  86.          
  87.           // call our orientation event handler
  88.           deviceOrientationHandler(tiltLR, tiltFB, dir);
  89.           }, false);
  90.       } else {
  91.         document.getElementById("doEvent").innerHTML = "Not supported on your device or browser.  Sorry."
  92.       }
  93.     }
  94.  
  95.  
  96.     // Reference page elements for dropping current device acceleration values into
  97. var accElem = document.getElementById('acceleration'),
  98.  accGravityElem = document.getElementById('acceleration-gravity'),
  99.  
  100.   // Define an event handler function for processing the device’s acceleration values
  101.    
  102.       handleDeviceMotionEvent = function(e) {
  103.    
  104.           // Get the current acceleration values in 3 axes and find the greatest of these
  105.    
  106.           var acc = e.acceleration,
  107.               maxAcc = Math.max(acc.x, acc.y, acc.z),
  108.    
  109.           // Get the acceleration values including gravity and find the greatest of these
  110.    
  111.               accGravity = e.accelerationIncludingGravity,
  112.               maxAccGravity = Math.max(accGravity.x, accGravity.y, accGravity.z);
  113.    
  114.           // Output to the user the greatest current acceleration value in any axis, as
  115.           // well as the greatest value in any axis including the effect of gravity
  116.    
  117.           accElem.innerHTML = 'Current acceleration: ' + maxAcc +  'm/s^2';
  118.           accGravityElem.innerHTML = 'Value incl. gravity: ' + maxAccGravity + 'm/s^2';
  119.       };
  120.    
  121.   // Assign the event handler function to execute when the device is moving
  122.    
  123.   window.addEventListener('devicemotion', handleDeviceMotionEvent, false);
  124.  
  125.     function deviceOrientationHandler(tiltLR, tiltFB, dir) {
  126.       document.getElementById("doTiltLR").innerHTML = Math.round(tiltLR);
  127.       document.getElementById("doTiltFB").innerHTML = Math.round(tiltFB);
  128.       document.getElementById("doDirection").innerHTML = Math.round(dir);
  129.       document.getElementById("acceleration").innerHTML = Math.max()
  130.      
  131.       // Apply the transform to the image
  132.       var logo = document.getElementById("imgLogo");
  133.       logo.style.webkitTransform = "rotate("+ tiltLR +"deg) rotate3d(1,0,0, "+ (tiltFB*-1)+"deg)";
  134.       logo.style.MozTransform = "rotate("+ tiltLR +"deg)";
  135.       logo.style.transform = "rotate("+ tiltLR +"deg) rotate3d(1,0,0, "+ (tiltFB*-1)+"deg)";
  136.     }
  137.    
  138.    
  139.     // Some other fun rotations to try...
  140.     //var rotation = "rotate3d(0,1,0, "+ (tiltLR*-1)+"deg) rotate3d(1,0,0, "+ (tiltFB*-1)+"deg)";
  141.     //var rotation = "rotate("+ tiltLR +"deg) rotate3d(0,1,0, "+ (tiltLR*-1)+"deg) rotate3d(1,0,0, "+ (tiltFB*-1)+"deg)";
  142.   </script>
  143.  
  144.  
  145.  
  146. </body>
  147. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement