JSFiddle - React, Tailwind, and code Playground
HTML
<div id="Border">
<div id="AddGraphsHere">
a
</div>
</div>
<button id="Button">
Click Here
</button>
<div id="Error">
TEXT
</div>
CSS
#Border {
border: #000000 5px solid;
width: 90%;
height: 200px;
}
#Graph {
width: 18%;
height: 190px;
float: left;
border: 1px solid black;
padding: 5px;
font-family: sans-serif;
font-size: 12px;
}
#Point {
width: 8px;
height: 8px;
border-radius: 100%;
border: 3px solid #0000FF;
background-color: #AAAAFF;
top: 100px;
position: absolute;
cursor: move;
}
JavaScript
var b = document.getElementById("Button");
var area = document.getElementById("AddGraphsHere");
var etwo;
var count = 0;
var error = document.getElementById("Error");
var point = 1;
var interval;
var elmnt;
var canExecute;
b.onclick = function addDiv() {
area.innerHTML += "<div id='Graph'><div onmouseover='dragElement(this, event)' id='Point'></div></div>";
point = document.getElementById('Point');
}
function falert() {alert("Hello!"); this.onmousedown = dragMouseDown;}
//Start with a dragElement(Graph);
function dragElement(elmnt, e) {
var pos1 = 0, pos2 = 0;
/* if present, the header is where you move the DIV from:*/
//error.innerHTML = elmnt;
document.addEventListener("mousedown", function () {dragMouseDown();});
function dragMouseDown(e) {
//error.innerHTML = "dragMouseDown Activated!";
e = e || window.event;
//alert(e);
// get the mouse cursor position at startup:
pos2 = e.clientY;
canExecute = true;
error.innerHTML = "a";
// call a function whenever the cursor moves:
document.addEventListener("mousemove", function () {elementDrag();});
//document.onmouseup = closeDragElement();
}
function elementDrag(e) {
if (canExecute === true) {
e = e || window.event;
count = count + 1;
// calculate the new cursor position:
//pos2 = e.clientY;
pos1 = pos2 - e.clientY;
pos2 = e.clientY;
// set the element's new position:
elmnt.style.position = "absolute";
elmnt.style.top = (elmnt.offsetTop - pos1) + "px";
//elmnt.top = (elmnt.offsetTop -
//pos1) + "px";
error.innerHTML = "(" + pos2 + " ; " + pos1 + "), " + count;
//error.innerHTML = elmnt.offsetTop + " - " + pos1;
document.addEventListener("mouseup", function() {closeDragElement();});
}
}
function closeDragElement() {
/* stop moving when mouse button is released:*/
document.onmouseup = null;
document.onmousemove = null;
...