Anonymous
Not logged in
Talk
Contributions
Create account
Log in
Publication Station
Search
Editing
Device orientation on the browser
(section)
From Publication Station
Namespaces
Page
Discussion
More
More
Page actions
Read
Edit
History
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=Example= See it running in: http://publicationstation.wdka.hro.nl/D&T/orientation/ ==code== <source lang="html4strict"> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script defer src="https://code.getmdl.io/1.2.1/material.min.js"></script> <style> body { margin: 2em; } </style> <title>Device orientation</title> <style type="text/css"> .h5logo { width: 50%; display: block; margin-left: auto; margin-right: auto; } </style> </head> <body> <div role="main" class="container"> <h1>Device Orientation</h1> <p>example from <a href="http://googlesamples.github.io/web-fundamentals/fundamentals/native-hardware/device-orientation/dev-orientation.html">http://googlesamples.github.io/web-fundamentals/fundamentals/native-hardware/device-orientation/dev-orientation.html</a></p> <p> Device orientation is <b><span id="doeSupported">not</span></b> supported on your device. </p> <img id="h5logo" src="http://publicationstation.wdka.hro.nl/wiki/images/8/85/Guttenberg.jpg" class="h5logo"> <h2>Rotation Data</h2> <p> <b>alpha:</b> <span id="alpha"></span><br> <b>beta:</b> <span id="beta"></span><br> <b>gamma:</b> <span id="gamma"></span><br> </p> <p> <b>Last updated:</b> <span id="timestamp"></span> </p> </div> <script type="text/javascript"> var fixed = 2; var h5logo = $("#h5logo"); var timestamp = $("#timestamp"); var alpha = $("#alpha"); var beta = $("#beta"); var gamma = $("#gamma"); /* // [START devori] */ if (window.DeviceOrientationEvent) { window.addEventListener('deviceorientation', deviceOrientationHandler, false); $("#doeSupported").innerText = ""; } /* // [END devori] */ var deviceOrientationData; function deviceOrientationHandler(evt) { deviceOrientationData = evt; try { timestamp.text( new Date(evt.timeStamp)); alpha.text( evt.alpha.toFixed(fixed) ); beta.text( evt.beta.toFixed(fixed) ); gamma.text( evt.gamma.toFixed(fixed) ); var rotation = "rotate("+ evt.alpha +"deg) rotate3d(1,0,0, "+ (evt.gamma * -1)+"deg)"; h5logo.css('transform', rotation).css('webkitTransform', rotation); } catch (ex) { $("EdoeSupported").text("NOT"); } } </script> </body> </html> </source> == Emulate device orientation== On a desktop computer the device orientation can be emulated by the browser. In Chrome sensors can be simulated by: * Opening the DevTools main menu, then * Under More Tools, clicking on Sensors https://developers.google.com/web/tools/chrome-devtools/device-mode/imgs/navigate-to-sensors.png More info at: https://developers.google.com/web/tools/chrome-devtools/device-mode/device-input-and-sensors ==more on Device orientation/motion== http://googlesamples.github.io/web-fundamentals/fundamentals/native-hardware/device-orientation/dev-orientation.html https://mobiforge.com/design-development/html5-mobile-web-device-orientation-events https://www.w3.org/TR/orientation-event/ https://www.html5rocks.com/en/tutorials/device/orientation/ ==debugging mobile browsers== [https://developer.mozilla.org/en-US/docs/Tools/Remote_Debugging/Debugging_Firefox_for_Android_over_Wifi debugging Firefox over Wifi]
Summary:
Please note that all contributions to Publication Station are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Publication Station:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation
Main navigation
Main page
Printmaking Studio
Print Studio
Dig. Publishing Studio
Namespaces
Grafiwiki
Random Page
Log in
Wiki tools
Wiki tools
Page tools
Page tools
User page tools
More
What links here
Related changes
Page information
Page logs