Note that there are some explanatory texts on larger screens.

plurals
  1. POCursor animation glitches if not allowed to finish
    primarykey
    data
    text
    <p>The issue I am having is that if the animation is not allowed to finish it will glitch. Other than that everything works how I planned. Also if you see any room for improvement that could be made to the "physics" to make it look a little more natural or exciting feel free to toss that in there! Also I am new to javascript so formatting advice would be greatly appreciated!! </p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Click Move&lt;/title&gt; &lt;script type="text/javascript"&gt; document.onmousedown = getCursorXY; function getCursorXY(e) { var cursorX = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft :document.body.scrollLeft); var cursorY = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); positionMessage(cursorX,cursorY); } function positionMessage(cursorX,cursorY){ if (!document.getElementById) return false; if (!document.getElementById("message")) return false; var elem = document.getElementById("message"); elem.style.position = "absolute"; moveElement("message",cursorX,cursorY,20); } function moveElement(elementID,cursorX,cursorY,interval) { if (!document.getElementById) return false; if (!document.getElementById(elementID)) return false; var elem = document.getElementById(elementID); var xpos = parseInt(elem.style.left); var ypos = parseInt(elem.style.top); if (xpos == cursorX &amp;&amp; ypos == cursorY) { return true; } if (xpos &lt; cursorX) { var dist = Math.sqrt(cursorX - xpos); xpos += dist; } if (xpos &gt; cursorX) { var dist = Math.sqrt((xpos - cursorX)); xpos -= dist; } if (ypos &lt; cursorY) { var dist = Math.sqrt((cursorY - ypos)); ypos += dist; } if (ypos &gt; cursorY) { var dist = Math.sqrt((ypos - cursorY)); ypos -= dist; } elem.style.left = xpos + "px"; elem.style.top = ypos + "px"; var repeat = "moveElement('"+elementID+"',"+cursorX+","+cursorY+","+interval+")"; movement = setTimeout(repeat,interval); } function updateSpan(element){ message = document.getElementById("message"); newMessage = document.getElementById(element.id); message.innerHTML = newMessage.id; } &lt;/script&gt; &lt;style type="text/css"&gt; #message { width: 90px; height: 50px; background:#999; z-index: 20; } #blue_box { position: absolute; top: 100px; left: 100px; width: 60px; height: 50px; background:#03F; } #red_box { position: absolute; top: 200px; left: 100px; width: 60px; height: 50px; background:#F00 } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="message" style="top:50px; left:100px;"&gt;WEEEEE!!!!!&lt;/div&gt; &lt;div id="blue_box" onclick="updateSpan(this)"&gt;Blue_Box&lt;/div&gt; &lt;div id="red_box" onclick="updateSpan(this)"&gt;Red_Box&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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