[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 ...
随机推荐
- SumatraPDF默认配置文件备份
background color of the non-document windows, traditionally yellow MainWindowBackground = #fff200 if ...
- LoibreOJ 2042. 「CQOI2016」不同的最小割 最小割树 Gomory-Hu tree
2042. 「CQOI2016」不同的最小割 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据 题目描述 ...
- c++11 初始化列表 bind function 示例
// 111111111111.cpp: 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #incl ...
- Arithmetic Slices LT413
A sequence of number is called arithmetic if it consists of at least three elements and if the diffe ...
- iframe高度自适应实现方案
iframe高度动态自适应,一直是个头疼的问题,今天我们从事件监听这个角度,来实现iframe高度实时更新. 方案一:监听iframe体的点击事件 <iframe src="casca ...
- 要显示的联系人——>自定义-bug
自定义中将“电话”下的“所有联系人”不勾选,但是Contacts列表还是显示PHONE联系人. SELECT _id, display_name, agg_presence.mode AS conta ...
- 关于部署传统的Dynamic Web项目
现在大部分都是采用maven构建的项目,但是偶尔也会遇到一些较老的项目,采用的是传统的动态Web项目. 我最近碰到这样一个项目,项目用的jar包都放在了WEB-INF/lib目录下.之前的人采用的部署 ...
- jvm运行机制和volatile关键字详解
参考https://www.cnblogs.com/dolphin0520/p/3920373.html JVM启动流程 1.java虚拟机启动的命令是通过java +xxx(类名,这个类中要有mai ...
- 栈(NOIP2003&水题测试2017082501)
题目链接:栈 这题不难. 我们看一下,其实可以发现是卡特兰数. 不知道卡特兰数?没事,给你简单讲一下. 卡特兰数的递推式f(n)=f(0)*f(n-1)+f(1)*f(n-2)+-+f(n-2)*f( ...
- PHP递归函数
递归函数(Recursive Function)是指直接或间接调用函数本身的函数 在每次调用自己时,必须是(在某种意义上)更接近 于解 必须有一个终止处理或计算的准则 function recursi ...