跨平台移动开发_PhoneGap 使用Accelerometer 加速器
使用Accelerometer 加速器效果图

示例代码
<!DOCTYPE html>
<html>
<head>
<title>
Cude PhoneGap Demo
</title>
<link
href="content/css/themes/default/jquery.mobile.structure-1.4.0-beta.1.min.css"
rel="stylesheet"
type="text/css"/>
<link href="content/css/themes/default/jquery.mobile-1.4.0-beta.1.min.css" rel="stylesheet" type="text/css"/>
<script src="content/js/jquery.js" type="text/javascript">
</script>
<script src="content/js/jquery.mobile-1.4.0-beta.1.js" type="text/javascript">
</script>
<script src="content/js/cordova.js" type="text/javascript">
</script>
<script src="content/scripts/xui-2.2.0.min.js">
</script>
<script src="content/scripts/emile.js">
</script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false); function onSuccess(acceleration) { var getCurrentAcceleration= 'Acceleration X: ' + acceleration.x + '<br />' +
'Acceleration Y: ' + acceleration.y + '<br />' +
'Acceleration Z: ' + acceleration.z + '<br />' +
'Timestamp: ' + acceleration.timestamp + '<br />'; x$('#getCurrentAcceleration').html('inner', getCurrentAcceleration);
};
function onError() {
alert('onError!');
}; var watchID = null; var options = { frequency: 1000 };
function onSuccess1(acceleration) { var watchAcceleration= 'Acceleration X: ' + acceleration.x + '<br />' +
'Acceleration Y: ' + acceleration.y + '<br />' +
'Acceleration Z: ' + acceleration.z + '<br />' +
'Timestamp: ' + acceleration.timestamp + '<br />'; x$('#watchAcceleration').html('inner', watchAcceleration);
fx(acceleration.x,acceleration.z*20 );
//fx(acceleration.y,acceleration.z*10 );
//fx(acceleration.timestamp);
}
function onError1() {
alert('onError!');
} function stopWatch() {
if (watchID) {
navigator.accelerometer.clearWatch(watchID);
watchID = null;
}
}
function onDeviceReady() {
navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);
watchID = navigator.accelerometer.watchAcceleration(onSuccess1, onError1, options);
}
</script>
<script>
function initialise()
{
styleshow();
dom();
//fx(1); }
//dom处理
function dom()
{
}
function SubString(s){
var str; // 声明变量。
str = s.substr(1,236); // 截取取字符串。
return(str); // 返回字符串。
}
//style 样式处理
function styleshow()
{ }
//style 动画、形变、渐变
function fx(valueid,valuez)
{
valueid=valueid*1000;
emile('box1', 'background:#008FFF;left:'+valuez+'px;padding-bottom:100px;opacity:1', {
duration: valueid, easing: bounce
});
emile('box2', 'background:#C8E919;left:'+valuez+'px;padding-bottom:100px;opacity:1', {
duration: valueid, easing: bounce
});
emile('box3', 'background:#AC193D;left:'+valuez+'px;top:400px;padding-bottom:100px;opacity:1', {
duration: valueid, easing: bounce
}); emile('box4', 'background:#008FFF;right:'+valuez+'px;padding-bottom:100px;opacity:1', {
duration: valueid, easing: bounce
});
emile('box5', 'background:#C8E919;right:'+valuez+'px;padding-bottom:100px;opacity:1', {
duration: valueid, easing: bounce
});
emile('box6', 'background:#AC193D;right:'+valuez+'px;top:200px;padding-bottom:100px;opacity:1', {
duration: valueid, easing: bounce
}); emile('boxb', 'left:500px;padding:10px;border:50px solid #5133AB', {
duration: 500,
after: function(){
emile('boxa', 'background:#D24726;left:100px;padding-bottom:100px;opacity:1', {
duration: valueid, easing: bounce
});
}
});
}
function bounce(pos) {
if (pos < (1/2.75)) {
return (7.5625*pos*pos);
} else if (pos < (2/2.75)) {
return (7.5625*(pos-=(1.5/2.75))*pos + .75);
} else if (pos < (2.5/2.75)) {
return (7.5625*(pos-=(2.25/2.75))*pos + .9375);
} else {
return (7.5625*(pos-=(2.625/2.75))*pos + .984375);
}
}
</script>
</head>
<body onload="initialise();">
<button onclick="stopWatch();">
停止监视动画
</button>
<div id="getCurrentAcceleration">
XYZ显示区
</div>
<div id="watchAcceleration">
XYZ显示区
</div>
<div id="box1" style="position:absolute;left:0px;background:#f00;opacity:0">
DIV动画区域块
</div>
<div
id="box2"
style="border:0px solid #00ff00;position:absolute;left:0px;top:200px;background:#000000">
DIV动画区域块
</div>
<div
id="box3"
style="border:0px solid #AC193D;position:absolute;left:0px;top:300px;background:#AC193D">
DIV动画区域块
</div> <div id="box4" style="position:absolute;right:0px;background:#f00;opacity:0">
DIV动画区域块
</div>
<div
id="box5"
style="border:0px solid #00ff00;position:absolute;right:0px;top:200px;background:#000000">
DIV动画区域块
</div>
<div
id="box6"
style="border:0px solid #AC193D;position:absolute;right:0px;top:150px;background:#AC193D">
DIV动画区域块
</div> <div id="boxa" style="position:absolute;left:0px;background:#D24726;opacity:0">
DIV
</div>
<div
id="boxb"
style="border:0px solid #00ff00;position:absolute;left:0px;top:350px;background:#362168"> DIV动画区域块
</div> </body>
</html>
代码示例包
声明:本博客高度重视知识产权保护,发现本博客发布的信息包含有侵犯其著作权的链接内容时,请联系我,我将第一时间做相应处理,联系邮箱ffgign@qq.com。
作者:Mark Fan (小念头) 来源:http://cube.cnblogs.com
说明:未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。如有疑问,可以通过 ffgign@qq.com 联系作者,本文章采用 知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议进行许可

跨平台移动开发_PhoneGap 使用Accelerometer 加速器的更多相关文章
- 跨平台移动开发_PhoneGap 使用Geolocation基于所在地理位置坐标调用百度地图API
使用Geolocation基于所在地理位置坐标调用百度地图API 效果图 示例代码 <!DOCTYPE html> <html> <head> <title& ...
- 跨平台移动开发_PhoneGap 警告,通知,鸣叫,振动4 种通知类型
创建鸣叫 使用 confirmation.beep 创建鸣叫 function playBeep() { navigator.notification.beep(1); } 创建振动 使用 ...
- 跨平台移动开发_PhoneGap 再次点击返回键切换到桌面效果
PhoneGap 再次点击返回键切换到桌面效果 相关代码 <!DOCTYPE html> <html> <head> <title> PhoneGap ...
- 跨平台移动开发_PhoneGap API Camera 使用摄像头采集照片.
camera对象提供对设备默认摄像头应用程序的访问. 程序运行效果 相关代码 <!DOCTYPE html> <html> <head> <title> ...
- 跨平台移动开发_PhoneGap API 事件类型
PhoneGap API Events backbuttondevicereadymenubuttonpauseresumeonlineofflinebatterycriticalbatterylow ...
- [.net 面向对象程序设计深入](5)MVC 6 —— 构建跨平台.NET开发环境(Windows/Mac OS X/Linux)
[.net 面向对象程序设计深入](5)MVC 6 —— 构建跨平台.NET开发环境(Windows/Mac OS X/Linux) 1.关于跨平台 上篇中介绍了MVC的发展历程,说到ASP.NET ...
- 全球首个全流程跨平台界面开发套件,PowerUI分析
一. 首个全流程跨平台界面开发套件,PowerUI正式发布 UIPower在DirectUI的基础上,自主研发全球首个全流程跨平台界面开发套件PowerUI(PUI)正式发布,PowerU ...
- 【转贴】-- 基于QT的跨平台应用开发
原帖地址:http://www.cnblogs.com/R0b1n/p/4106613.html 1 Qt简介 Qt是1991年奇趣科技开发的一个跨平台的C++图形用户界面应用程序框架.它提供给应用程 ...
- 新成员!Visual Studio Code --跨平台的开发工具(支持OSX, Linux 和 Windows)
原文出处:新成员!Visual Studio Code --跨平台的开发工具(支持OSX, Linux 和 Windows) 这是我的文章备份 http://www.dotblogs.com.tw/ ...
随机推荐
- modelform 对象和model之间的关系
一.modelform的每一个标签对象 for bound_field in form: print('form.model',form.Meta.model) ...
- dva解读1
1.首先定义一个app对象实现dva const app = dva({ history: createHistory(), }); // 2. Plugins app.use(createLoadi ...
- NGUI Checkbox与PlayerPrefs
UICheckboxPrefs.cs 1,bool isChecked:false 为“初始”状态,true为“选中”: 2,bool startsChecked:true,一运行,就显示UISpri ...
- 巨蟒python全栈开发django5:组件&&CBV&FBV&&装饰器&&ORM增删改查
内容回顾: 补充反向解析 Html:{% url ‘别名’ 参数 %} Views:reverse(‘别名’,args=(参数,)) 模板渲染 变量 {{ 变量名 }} 逻辑相关 {% %} 过滤器: ...
- POJ 1408 Fishnet【枚举+线段相交+叉积求面积】
题目: http://poj.org/problem?id=1408 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- How to make asynchronous HTTP requests in PHP 4种PHP异步执行的常用方式
[是否等待返回就执行下一步] How to make asynchronous HTTP requests in PHP - Stack Overflow https://stackoverflow. ...
- do not use numbers as enumeration values
w 字段类型设置错误 有限元的判断,勿用枚举行. MySQL :: MySQL 5.7 Reference Manual :: 12.4.4 The ENUM Typehttps://dev.mysq ...
- 查找杀死指定进程delphi
//需要引用tlhelp32单元//查找进程function findProcessId(pname:string):Cardinal; var hsnapshot:THandle; lpe:TPro ...
- Wireshark网络分析工具(二)
一.TCP三次握手过称 1. 第一次握手的数据包 客户端发送一个TCP,标志位为SYN,序列号为0, 代表客户端请求建立连接. 如下图: 2. 第二次握手的数据包 服务器发回确认包, 标志位为 SYN ...
- unity坑faq
遇到的坑记录下来,大都都是听说,没有实测 1. Graphics.copyTexture,在某些机型上不支持从不同类型拷贝 2. msaa 小米mix2不支持,晓龙845 3. android4.2下 ...