forked from musclesoft/jquery-connections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.html
101 lines (90 loc) · 2.27 KB
/
example.html
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>js-connections</title>
<script src="js-connections.js"></script>
</head>
<style>
div {
background: rgb(255, 255, 255);
background: rgba(255, 255, 255, 0.7);
float: left;
min-width: 4em;
min-height: 3em;
max-width: 29ex;
margin: 3em;
padding: 1em;
border: 1px solid rgb(200, 200, 200);
border: 1px solid rgba(0, 0, 0, 0.2);
border-radius: 16px;
box-shadow: 2px 5px 5px rgba(0, 0, 0, 0.2);
}
connection {
z-index: -1;
border: 3px solid;
border-radius: 7em;
color: rgb(128, 128, 128);
color: rgba(0, 0, 0, 0.5);
}
connection.odd {
border-radius: 100%;
}
connection.first {
color: black;
border: 5px dotted;
}
</style>
<body>
<div id="one">div 1
</div>
<div id="two">div 2
</div>
<div id="three">div 3
</div>
<div id="four" style="width: 100px; height: 100px; background-color: lightblue; position: absolute; top: 300px; left: 350px; cursor: grab;">
Drag Me
</div>
<script>
const d1 = document.getElementById("one");
const d2 = document.getElementById("two");
const d3 = document.getElementById("three");
const draggable = document.getElementById("four");
let isDragging = false;
let offsetX = 0;
let offsetY = 0;
draggable.addEventListener("mousedown", (e) => {
isDragging = true;
offsetX = e.clientX - draggable.offsetLeft;
offsetY = e.clientY - draggable.offsetTop;
draggable.style.cursor = "grabbing";
});
document.addEventListener("mousemove", (e) => {
if (isDragging) {
draggable.style.left = `${e.clientX - offsetX}px`;
draggable.style.top = `${e.clientY - offsetY}px`;
}
});
document.addEventListener("mouseup", () => {
isDragging = false;
draggable.style.cursor = "grab";
});
d1.connections({
to: ['#two', '#four'],
});
d2.connections({
to: '#three',
})
d3.connections({
to: '#four'
})
//d1.connections("destroy");
setInterval(() => {
d1.connections("update");
d2.connections("update");
d3.connections("update");
}, 100);
</script>
</body>
</html>