-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
62 lines (61 loc) · 1.22 KB
/
index.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
<!doctype html>
<html>
<head>
<title>Click me</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body, html {
width: 100%;
height: 100%;
font: 14px Helvetica, Arial;
}
body {
display: flex;
align-items: center;
justify-content: center;
}
h1 {
font-size: 30px;
}
button {
margin: 20px;
padding: 10px 20px;
outline: none;
border: none;
border-radius: 10px;
background: blue;
color: #fff;
font: 24px Helvetica, Arial;
cursor: pointer;
}
.wrapper {
text-align: center;
}
</style>
</head>
<body>
<div class="wrapper">
<h1>I was clicked <span id="counter"></span> times!</h1>
<button id="button">Click Me</button>
</div>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
var button = document.getElementById("button");
var counter = document.getElementById("counter");
socket.on('loaded', function(count) {
counter.innerHTML = count;
});
button.onclick = function() {
socket.emit('button click', true);
}
socket.on('button click', function(count) {
counter.innerHTML = count;
});
</script>
</body>
</html>