Note that there are some explanatory texts on larger screens.

plurals
  1. POMoving of object using accelerometer in ipad
    text
    copied!<p>Hi i am building an app in ipad where i have object, when i move the ipad even object should move using acccelerometer functionalities.But when i use the below code its not entering inside the <code>Mobeobject()</code> functionality may i know where iam going wrong.</p> <p>my object is not moving.</p> <pre><code>// Start moving the object var startMove = $('#startMove'); startMove.live("click",function() { alert("startMoving&gt;&gt;"); 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 &lt; 0 &amp;&amp; objPosition.left &lt;= rightBoundary ) { myObj.animate({ left:'+=10' },100); } else if( acceleration.x &gt; 0 &amp;&amp; objPosition.left &gt; leftBoundary ) { myObj.animate({ left:'-=10' },100); } if( acceleration.y &lt; 0 &amp;&amp; objPosition.top &gt; topBoundary ) { myObj.animate({ top:'-=10' },100); } else if(acceleration.y &gt; 0 &amp;&amp; objPosition.top &lt;= bottomBoundary ) { myObj.animate({ top:'+=10' },100); } } </code></pre> <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;body&gt; &lt;div data-role="page"&gt; &lt;div data-role="content"&gt; &lt;div id="obj_wall"&gt; &lt;div id="obj"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div&gt; &lt;a href="#" id="startMove" data-role="button"&gt;Start Moving&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p> </p> <p> Start Moving </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload