[device-orientation] 使用手机设备的方向感应实现图片选择
- <div class="main">
- <h2>Device Orientation</h2>
- <table>
- <tbody><tr>
- <td>Event Supported</td>
- <td id="doEvent">DeviceOrientation</td>
- </tr>
- <tr>
- <td>Tilt Left/Right [gamma]</td>
- <td id="doTiltLR"></td>
- </tr>
- <tr>
- <td>Tilt Front/Back [beta]</td>
- <td id="doTiltFB"></td>
- </tr>
- <tr>
- <td>Direction [alpha]</td>
- <td id="doDirection"></td>
- </tr>
- </tbody></table>
- </div>
- <div class="container" style="-webkit-perspective: 300; perspective: 300;">
- <img src="zhenge.jpg" id="imgLogo" class="logo">
- </div>
- <script type="text/javascript">
- init();
- var count = 0;
- function init() {
- if (window.DeviceOrientationEvent) {
- document.getElementById("doEvent").innerHTML = "DeviceOrientation";
- // Listen for the deviceorientation event and handle the raw data
- window.addEventListener('deviceorientation', function(eventData) {
- // gamma is the left-to-right tilt in degrees, where right is positive
- var tiltLR = eventData.gamma;
- // beta is the front-to-back tilt in degrees, where front is positive
- var tiltFB = eventData.beta;
- // alpha is the compass direction the device is facing in degrees
- var dir = eventData.alpha
- // call our orientation event handler
- deviceOrientationHandler(tiltLR, tiltFB, dir);
- }, false);
- } else {
- document.getElementById("doEvent").innerHTML = "Not supported on your device or browser. Sorry."
- }
- }
- function deviceOrientationHandler(tiltLR, tiltFB, dir) {
- document.getElementById("doTiltLR").innerHTML = Math.round(tiltLR);
- document.getElementById("doTiltFB").innerHTML = Math.round(tiltFB);
- document.getElementById("doDirection").innerHTML = Math.round(dir);
- // Apply the transform to the image
- var logo = document.getElementById("imgLogo");
- logo.style.webkitTransform = "rotate("+ tiltLR +"deg) rotate3d(1,0,0, "+ (tiltFB*-1)+"deg)";
- logo.style.MozTransform = "rotate("+ tiltLR +"deg)";
- logo.style.transform = "rotate("+ tiltLR +"deg) rotate3d(1,0,0, "+ (tiltFB*-1)+"deg)";
- }
- // Some other fun rotations to try...
- //var rotation = "rotate3d(0,1,0, "+ (tiltLR*-1)+"deg) rotate3d(1,0,0, "+ (tiltFB*-1)+"deg)";
- //var rotation = "rotate("+ tiltLR +"deg) rotate3d(0,1,0, "+ (tiltLR*-1)+"deg) rotate3d(1,0,0, "+ (tiltFB*-1)+"deg)";
- </script>
测试手机:
GT - I9300 , 系统版本 3.03 , 微信下面正常 , UC V10.8.5.689 可以
iPhone 4s ,ios 版本 7.1.2 , safari浏览器可以, 微信可以
[device-orientation] 使用手机设备的方向感应实现图片选择的更多相关文章
- 【HTML5 】手机重力与方向感应的应用——摇一摇效果
http://www.helloweba.com/view-blog-287.html HTML5有一个重要特性:DeviceOrientation,它将底层的方向和运动传感器进行了高级封装,它使我们 ...
- javascript检查移动设备是否支持重力方向感应
javascript如何检查移动设备,如手机平台是否支持重力或者方向感应. 可以使用html5提供的重力和方向感应接口来判断. html5 中针对高端手机提供了重力感应和重力加速的接口,开发可以利用这 ...
- 获取Android设备的方向,Sensor和SensorManager实现手机旋转角度
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2012/1009/425.html 带有g-sensor的Android设备上可通过API ...
- Android Device Orientation
最近在处理相机拍照的方向问题,在Android Device的Orientation问题上有了些疑问,就顺便写个Demo了解下Android Device Orientation究竟是怎么个判断. A ...
- 配置Xcode的Device Orientation、AppIcon、LaunchImage
以下图片指出的 TARGETS→General 面板的信息. 下面我们讲讲根据 APP 需求配置我们的Xcode: 1.设置 Device Orientation,指定 APP 支持设备的方向 ,我们 ...
- iOS设备的重力感应
重力感应是每台iOS设备都具备的功能,所以在应用用好重力感应会有意想不到的效果 1.添加CoreMotion框架 2.在需要使用重力感应的类中添加头文件 #import <CoreMotion/ ...
- PHP简单判断手机设备的方法
本文实例讲述了PHP简单判断手机设备的方法.分享给大家供大家参考,具体如下: 现在移动互联网越来越发到,很多的网站都普及了手机端浏览,为了更好的让网页在手机端显示,我们都选择了使用CSS媒体查询制作响 ...
- ios获取设备手持方向——电子罗盘
转:http://book.51cto.com/art/201411/457105.htm 2014-11-15 19:07 张亚飞/崔巍 中国铁道出版社 字号:T | T 综合评级: 想读() 在 ...
- [中英对照]Device Drivers in User Space: A Case for Network Device Driver | 用户态设备驱动: 以网卡驱动为例
前文初步介绍了Linux用户态设备驱动,本文将介绍一个典型的案例.Again, 如对Linux用户态设备驱动程序开发感兴趣,请阅读本文,否则请飘过. Device Drivers in User Sp ...
随机推荐
- 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 ...
- Windows cordova build Error: Could not find gradle wrapper within Android SDK.(转)
原文:http://blog.csdn.net/kongxx/article/details/68954151 在Windows7上运行 “cordova build Android” 报错,如下: ...
- KeyPress键盘按键ASCII值对应表
vbKeyLButton 1 鼠标左键 vbKeyRButton 2 鼠标右键 vbKeyCancel 3 CANCEL 键 vbKeyMButton 4 鼠标中键 vbKeyBack 8 B ...
- UI设计教程分享:让你彻底读懂字体
一份普普通通.规规矩矩的设计 一份让人印象深刻.新颖有趣的设计 差在哪?其实就差在三个字上! “优秀的设计不是每一个细节都有亮点,而是弱化其他元素,让某一个亮点最大化.” 今天“骉叔的设计心得”就来总 ...
- python早期看书笔记
- Bubble(冒泡排序)————Java
用Java进行冒泡排序的代码,利用一个flag进行优化算法: import java.util.Scanner; public class Bubble_Sort { private static i ...
- OpenCV(1):显示图像
显示图像 #include<iostream> #include<opencv2/core/core.hpp> #include<opencv2/highgui/high ...
- 6. Uniforms in American's Eyes 美国人眼里的制服
6. Uniforms in American's Eyes 美国人眼里的制服 (1) Americans are proud of their variety and individuality,y ...
- python code(1)
from collections import UserList class MthChianList(UserList): def filter(self,predicste): return Mt ...
- Win7 VS2015环境编译NanoVG
书接上回,Cairo编译好使用后,发现简单的每帧画100条随机线段就卡得不行,装了个gooreplacer( http://liujiacai.net/gooreplacer/ )上stackover ...