-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructuregen.js
More file actions
66 lines (55 loc) · 1.99 KB
/
structuregen.js
File metadata and controls
66 lines (55 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//Make the DIV element draggagle:
dragElement(document.getElementsByClassName("circle"));
function dragElement(circleClass) {
alert("hey")
var elmnt = circleClass[0];
document.onmousedown = elementDecide;
function elementDecide(e) {
e = e || window.event;
// Save current mouse location
var currentMouseX = e.clientX;
var currentMouseY = e.clientY;
// Decide which circle is being selected
for (i = 0; i < circleClass.length; i++) {
elmnt = circleClass[i]
var distanceX = (elmnt.getAttribute("cx") - (currentMouseX - 8))*(elmnt.getAttribute("cx") - (currentMouseX - 8))
var distanceY = (elmnt.getAttribute("cy") - (currentMouseY - 115))*(elmnt.getAttribute("cy") - (currentMouseY - 115))
console.log(i)
console.log("Distances: (" + distanceX + ", " + distanceY + ")")
if (distanceX + distanceY < 1650) {
console.log(i + " is moving")
new dragMouseDown;
break;
}
}
}
function dragMouseDown(e) {
e = e || window.event;
// get the mouse cursor position at startup:
document.onmouseup = closeDragElement;
// call a function whenever the cursor moves:
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e = e || window.event;
// calculate the new cursor position:
// set the element's new position:
// elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
// elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
elmnt.setAttribute("cx", e.clientX - 8)
elmnt.setAttribute("cy", e.clientY - 115)
}
function closeDragElement(e) {
e = e || window.event;
// stop moving when mouse button is released:
// window.alert((elmnt.attr(cx))
var diameter = elmnt.getAttribute("r")*2;
if (((e.clientX - 8) % diameter > 0) || ((e.clientY - 115) % diameter > 0)){
// move to better spot
elmnt.setAttribute("cx", (Math.round((e.clientX - 8)/diameter)*diameter));
elmnt.setAttribute("cy", (Math.round((e.clientY - 115)/diameter)*diameter));
}
document.onmouseup = null;
document.onmousemove = null;
}
}