嗨,我在iPad中建立一个应用程序,我有对象,当我移动ipad甚至对象应该使用acccelerometer功能移动。但是当我使用下面的代码时,它不会进入Mobeobject()
功能我可以知道哪里出错了。在ipad中使用加速度计移动对象
我的对象不动。
// Start moving the object
var startMove = $('#startMove');
startMove.live("click",function()
{
alert("startMoving>>");
startMoving();
$(this).hide();
});
// Start watching the acceleration
function startMoving(){
alert("startMoving");
var options = { frequency: 500 };
alert("insidestartMoving");
watchMove = navigator.accelerometer.watchAcceleration(moveObject, onError, options);
alert("instartMoving");
}
// moveObject
function moveObject(acceleration) {
alert("moveObject");
var myObj = $('#obj');
var wall = $('#obj_wall');
var objPosition = myObj.position();
var leftBoundary = 0;
var topBoundary = 0;
var rightBoundary = wall.width() - myObj.width() - 10; // 10 represents the 10px for the margin
var bottomBoundary = wall.height() - myObj.height() - 10; // 10 represents the 10px for the margin
if(acceleration.x < 0 && objPosition.left <= rightBoundary) {
myObj.animate({
left:'+=10'
},100);
} else if(acceleration.x > 0 && objPosition.left > leftBoundary) {
myObj.animate({
left:'-=10'
},100);
}
if(acceleration.y < 0 && objPosition.top > topBoundary) {
myObj.animate({
top:'-=10'
},100);
} else if(acceleration.y > 0 && objPosition.top <= bottomBoundary) {
myObj.animate({
top:'+=10'
},100);
}
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<body>
<div data-role="page">
<div data-role="content">
<div id="obj_wall">
<div id="obj"></div>
</div>
<div>
<a href="#" id="startMove" data-role="button">Start Moving</a>
</div>
</div>
</div>
开始移动
你可以在上面的代码中添加startMove按钮吗? – 2013-02-15 06:33:17
@ClintonWard我编辑了代码,并张贴上面.. ..可以检查它的按钮method.its进入看到之后,它不进入moveobject(加速度) – crazy2431 2013-02-15 06:41:59
你试过使用最新的科尔多瓦? 2.4.0 – 2013-02-15 08:56:19