-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrolx - Copy.html
158 lines (147 loc) · 4.08 KB
/
controlx - Copy.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="http://code.interactjs.io/v1.3.4/interact.min.js"></script>
<script>
// target elements with the "draggable" class
interact('.draggable')
.draggable({
// enable inertial throwing
inertia: true,
// keep the element within the area of it's parent
restrict: {
restriction: "parent",
endOnly: true,
elementRect: { top: 0, left: 0, bottom: 1, right: 1 }
},
// enable autoScroll
autoScroll: true,
// call this function on every dragmove event
onmove: dragMoveListener,
// call this function on every dragend event
onend: function (event) {
var textEl = event.target.querySelector('p');
textEl && (textEl.textContent =
'moved a distance of '
+ (Math.sqrt(Math.pow(event.pageX - event.x0, 2) +
Math.pow(event.pageY - event.y0, 2) | 0))
.toFixed(2) + 'px');
}
});
var ws = new WebSocket("ws://127.0.0.1:5678/")
var yValue2 = "";
var currentvalue = 0;
ws.onmessage = function (event) {
var wholedata = event.data;
alert(event.data)
var res2 = wholedata;
yValue2 = res2;
};
function dragMoveListener (event) {
var target = event.target,
// keep the dragged position in the data-x/data-y attributes
x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx,
y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;
// translate the element
target.style.webkitTransform =
target.style.transform =
'translate(' + x + 'px, ' + y + 'px)';
// update the posiion attributes
target.setAttribute('data-x', x);
target.setAttribute('data-y', y);
}
// this is used later in the resizing and gesture demos
window.dragMoveListener = dragMoveListener;
</script>
<style>
.container {
display: grid;
grid-template-columns: 1fr 1fr;
}
.container > div {
flex: 1; /*grow*/
}
.container div{
position: relative;
width: 500px;
height: 360px;
background-color: black;
}
#d1{
background:transparent;
border-style: solid;
border-color:#20C20E;
font-size:large;
text-align:center;
line-height:150px;
user-select: none;
display : block;
width: "25%";
height: "25%";
margin: 5px auto;
}
#d2{
background:transparent;
border-style: solid;
border-color:#20C20E;
font-size:large;
text-align:center;
line-height:150px;
user-select: none;
display : block;
width: "25%";
height: "25%";
margin: 5px auto;
}
#d3{
background:transparent;
border-style: solid;
border-color:#20C20E;
font-size:large;
text-align:center;
line-height:150px;
user-select: none;
display : block;
width: "25%";
height: "25%";
margin: 5px auto;
}
</style>
<head>
<title>
webpage
</title>
<link rel="stylesheet" href="http://anijs.github.io/lib/anicollection/anicollection.css">
<link rel="stylesheet" href="magic.css">
</head>
<body style="background-color:black;text-align:center">
<script>
var ws = new WebSocket("ws://127.0.0.1:5678/"),
messages = document.createElement('ul');
ws.onmessage = function (event) {
alert(yValue2)
if (yValue2 == "0"){
document.getElementById('d1').style.borderColor = "pink"
}
if (yValue2 == "1"){
document.getElementById('d2').style.borderColor = "pink"
}
if (yValue2 == "2"){
document.getElementById('d3').style.borderColor = "pink"
}
};
document.body.appendChild(messages);
</script>
<div class="container">
<div id="d1" class="draggable">
<p></p>
</div>
<div id="d2" class="draggable">
<p></p>
</div>
<div id="d3" class="draggable">
<p></p>
</div>
<br style="clear: left;" />
</div>
</body>
</html>