Note that there are some explanatory texts on larger screens.

plurals
  1. POfunction won't execute (correctly) more than once
    primarykey
    data
    text
    <p>I'm trying to change the position of a div following these guidlines to make it look fluid:</p> <ul> <li>very small increments at a time</li> <li>numerous times per second</li> <li>at a given angle(hence all the trig in endpoint())</li> </ul> <p>I have tested my function, "endpoint()", which handles the calculation and movement of the div and it works as intended. However, when I try to execute the function more than once, it doesn't work.</p> <pre><code>&lt;style type="text/css"&gt; .ball { width:20px; height:20px; border-radius:50%; background-color:#00c0c6; position:absolute; left:0px; top:0px; } &lt;/style&gt; &lt;div id="tehBall" class="ball"&gt;&lt;/div&gt; &lt;script type="text/javascript"&gt; endpoint(slopeInRadians); //WORKS! (changes position of the div) endpoint(slopeInRadians); //DOESN'T work (doesn't change the position of the div) endpoint(slopeInRadians); //DOESN'T work (same as above) &lt;/script&gt; </code></pre> <p>here is the code for endpoint function:</p> <pre><code>function endpoint(m) { var oldX = getStyle("tehBall", "left"); var oldY = getStyle("tehBall", "top"); var xAxis = parseInt(oldX); var yAxis = parseInt(oldY); var dX = (Math.cos(m)); var dY = ((0 - Math.sin(m))); xAxis += dX; yAxis += dY; xAxis = xAxis.toString(); yAxis = yAxis.toString(); xAxis += "px"; yAxis += "px"; document.getElementById('tehBall').style.left = xAxis; document.getElementById('tehBall').style.top = yAxis; } </code></pre> <p>code for getStyle(used in endpoint function):</p> <pre><code>function getStyle(id, property){ var elem = document.getElementById(id); var value = window.getComputedStyle(elem,null).getPropertyValue(property); return value; } </code></pre> <p>any help would be much appreciated </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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