1. <div class="main">
  2. <h2>Device Orientation</h2>
  3. <table>
  4. <tbody><tr>
  5. <td>Event Supported</td>
  6. <td id="doEvent">DeviceOrientation</td>
  7. </tr>
  8. <tr>
  9. <td>Tilt Left/Right [gamma]</td>
  10. <td id="doTiltLR"></td>
  11. </tr>
  12. <tr>
  13. <td>Tilt Front/Back [beta]</td>
  14. <td id="doTiltFB"></td>
  15. </tr>
  16. <tr>
  17. <td>Direction [alpha]</td>
  18. <td id="doDirection"></td>
  19. </tr>
  20. </tbody></table>
  21. </div>
  22.  
  23. <div class="container" style="-webkit-perspective: 300; perspective: 300;">
  24. <img src="zhenge.jpg" id="imgLogo" class="logo">
  25. </div>
  26.  
  27. <script type="text/javascript">
  28. init();
  29. var count = 0;
  30.  
  31. function init() {
  32. if (window.DeviceOrientationEvent) {
  33. document.getElementById("doEvent").innerHTML = "DeviceOrientation";
  34. // Listen for the deviceorientation event and handle the raw data
  35. window.addEventListener('deviceorientation', function(eventData) {
  36. // gamma is the left-to-right tilt in degrees, where right is positive
  37. var tiltLR = eventData.gamma;
  38.  
  39. // beta is the front-to-back tilt in degrees, where front is positive
  40. var tiltFB = eventData.beta;
  41.  
  42. // alpha is the compass direction the device is facing in degrees
  43. var dir = eventData.alpha
  44.  
  45. // call our orientation event handler
  46. deviceOrientationHandler(tiltLR, tiltFB, dir);
  47. }, false);
  48. } else {
  49. document.getElementById("doEvent").innerHTML = "Not supported on your device or browser. Sorry."
  50. }
  51. }
  52.  
  53. function deviceOrientationHandler(tiltLR, tiltFB, dir) {
  54. document.getElementById("doTiltLR").innerHTML = Math.round(tiltLR);
  55. document.getElementById("doTiltFB").innerHTML = Math.round(tiltFB);
  56. document.getElementById("doDirection").innerHTML = Math.round(dir);
  57.  
  58. // Apply the transform to the image
  59. var logo = document.getElementById("imgLogo");
  60. logo.style.webkitTransform = "rotate("+ tiltLR +"deg) rotate3d(1,0,0, "+ (tiltFB*-1)+"deg)";
  61. logo.style.MozTransform = "rotate("+ tiltLR +"deg)";
  62. logo.style.transform = "rotate("+ tiltLR +"deg) rotate3d(1,0,0, "+ (tiltFB*-1)+"deg)";
  63. }
  64.  
  65. // Some other fun rotations to try...
  66. //var rotation = "rotate3d(0,1,0, "+ (tiltLR*-1)+"deg) rotate3d(1,0,0, "+ (tiltFB*-1)+"deg)";
  67. //var rotation = "rotate("+ tiltLR +"deg) rotate3d(0,1,0, "+ (tiltLR*-1)+"deg) rotate3d(1,0,0, "+ (tiltFB*-1)+"deg)";
  68. </script>

测试手机:

GT - I9300 , 系统版本 3.03 , 微信下面正常 , UC V10.8.5.689 可以

iPhone 4s ,ios 版本 7.1.2 , safari浏览器可以, 微信可以

[device-orientation] 使用手机设备的方向感应实现图片选择的更多相关文章

  1. 【HTML5 】手机重力与方向感应的应用——摇一摇效果

    http://www.helloweba.com/view-blog-287.html HTML5有一个重要特性:DeviceOrientation,它将底层的方向和运动传感器进行了高级封装,它使我们 ...

  2. javascript检查移动设备是否支持重力方向感应

    javascript如何检查移动设备,如手机平台是否支持重力或者方向感应. 可以使用html5提供的重力和方向感应接口来判断. html5 中针对高端手机提供了重力感应和重力加速的接口,开发可以利用这 ...

  3. 获取Android设备的方向,Sensor和SensorManager实现手机旋转角度

    http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2012/1009/425.html 带有g-sensor的Android设备上可通过API ...

  4. Android Device Orientation

    最近在处理相机拍照的方向问题,在Android Device的Orientation问题上有了些疑问,就顺便写个Demo了解下Android Device Orientation究竟是怎么个判断. A ...

  5. 配置Xcode的Device Orientation、AppIcon、LaunchImage

    以下图片指出的 TARGETS→General 面板的信息. 下面我们讲讲根据 APP 需求配置我们的Xcode: 1.设置 Device Orientation,指定 APP 支持设备的方向 ,我们 ...

  6. iOS设备的重力感应

    重力感应是每台iOS设备都具备的功能,所以在应用用好重力感应会有意想不到的效果 1.添加CoreMotion框架 2.在需要使用重力感应的类中添加头文件 #import <CoreMotion/ ...

  7. PHP简单判断手机设备的方法

    本文实例讲述了PHP简单判断手机设备的方法.分享给大家供大家参考,具体如下: 现在移动互联网越来越发到,很多的网站都普及了手机端浏览,为了更好的让网页在手机端显示,我们都选择了使用CSS媒体查询制作响 ...

  8. ios获取设备手持方向——电子罗盘

    转:http://book.51cto.com/art/201411/457105.htm 2014-11-15 19:07 张亚飞/崔巍 中国铁道出版社 字号:T | T 综合评级: 想读()  在 ...

  9. [中英对照]Device Drivers in User Space: A Case for Network Device Driver | 用户态设备驱动: 以网卡驱动为例

    前文初步介绍了Linux用户态设备驱动,本文将介绍一个典型的案例.Again, 如对Linux用户态设备驱动程序开发感兴趣,请阅读本文,否则请飘过. Device Drivers in User Sp ...

随机推荐

  1. How to program BMW KOMBI and NBTwith ENET E sys cable ICOM A2

    This is how to set up Router or DHCP server for BMW KOMBI and NBT programming with Enet e sys cable ...

  2. Windows cordova build Error: Could not find gradle wrapper within Android SDK.(转)

    原文:http://blog.csdn.net/kongxx/article/details/68954151 在Windows7上运行 “cordova build Android” 报错,如下: ...

  3. KeyPress键盘按键ASCII值对应表

    vbKeyLButton 1 鼠标左键  vbKeyRButton 2 鼠标右键  vbKeyCancel 3 CANCEL 键  vbKeyMButton 4 鼠标中键  vbKeyBack 8 B ...

  4. UI设计教程分享:让你彻底读懂字体

    一份普普通通.规规矩矩的设计 一份让人印象深刻.新颖有趣的设计 差在哪?其实就差在三个字上! “优秀的设计不是每一个细节都有亮点,而是弱化其他元素,让某一个亮点最大化.” 今天“骉叔的设计心得”就来总 ...

  5. python早期看书笔记

  6. Bubble(冒泡排序)————Java

    用Java进行冒泡排序的代码,利用一个flag进行优化算法: import java.util.Scanner; public class Bubble_Sort { private static i ...

  7. OpenCV(1):显示图像

    显示图像 #include<iostream> #include<opencv2/core/core.hpp> #include<opencv2/highgui/high ...

  8. 6. Uniforms in American's Eyes 美国人眼里的制服

    6. Uniforms in American's Eyes 美国人眼里的制服 (1) Americans are proud of their variety and individuality,y ...

  9. python code(1)

    from collections import UserList class MthChianList(UserList): def filter(self,predicste): return Mt ...

  10. Win7 VS2015环境编译NanoVG

    书接上回,Cairo编译好使用后,发现简单的每帧画100条随机线段就卡得不行,装了个gooreplacer( http://liujiacai.net/gooreplacer/ )上stackover ...