Note that there are some explanatory texts on larger screens.

plurals
  1. PO(my) Drag and Drop (javascript) doesn't work properly with text
    primarykey
    data
    text
    <p>my javascript drag and drop engine (still working on it) doesn't work on the second drag if there is text involved. It still behaves normally except if you click the <code>&lt;p id="square" onmousedown="drag(event)"&gt;meep&lt;/p&gt;</code>, the text drops down and follows you from not where you clicked- but from just below (a few cm) where you clicked. On the other hand, if I use a <code>&lt;div&gt;</code> with no text, it works perfectly.</p> <pre><code>// JavaScript Document var posX; var posY; var element; function drag(event) { element = document.getElementById("square"); posX = event.clientX -parseInt(element.offsetLeft); posY = event.clientY -parseInt(element.offsetTop); document.addEventListener("mousemove", move, false); } function move(event) { if (typeof(document.getElementById("square").mouseup) == "undefined") element.addEventListener("mouseup", drop, false); //Prevents redundantly adding the same event handler repeatedly element.style.left = event.clientX - posX + "px"; element.style.top = event.clientY - posY + "px"; } function drop() { document.removeEventListener("mousemove", move, false); element.removeEventListener("mouseup", drop, false); } </code></pre> <p>And the html is either:</p> <p><code>&lt;div id="square" onmousedown="drag(event)"&gt;&lt;/div&gt;</code></p> <p>or</p> <p><code>&lt;p id="square" onmousedown="drag(event)"&gt;meep&lt;/p&gt;</code></p> <p>and some css to save time:</p> <pre><code>#square { position: relative; width: 100px; height: 100px; background: red; } </code></pre> <p>Thank you all for your answers and your time!</p> <p>EDIT: A <code>&lt;div&gt;</code> seems to work perfectly with text in it, but not a <code>&lt;p&gt;</code></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.
    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