-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
66 lines (63 loc) · 2.41 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
63
64
65
66
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script>
<!doctype html>
<html>
<head>
<title>Socket.IO chat</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 13px Helvetica, Arial; }
form { background: #777; padding: 3px; position: fixed; bottom: 0; width: 100%; }
form input { border: 0; padding: 10px; width:80%; }
form select { border: 0; padding: 10px; }
form button { background: rgb(130, 224, 255); border: none; padding: 10px; }
#messages { list-style-type: none; margin: 0; padding: 0; padding-bottom:25px; margin-bottom:25px; }
#messages li { padding: 5px 10px; }
#messages li:nth-child(odd) { background: #eee; }
</style>
</head>
<body>
<ul id="messages"></ul>
<form action="">
<table>
<tr>
<td style="width:50%;">Nome: <input id="nome" autocomplete="off" /></td>
<td>Contexto: <select id="contexto">
<option value="quem é">Quem é</option>
<option value="o que">O que é</option>
<option value="historia">História de</option>
</select></td>
<td>Quantidade: <select id="quantidade">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select></td>
<td><button>Send</button></td>
</tr>
</table>
</form>
</body>
</html>
<script>
let socket = io();
$(function () {
var socket = io();
$('form').submit(function(e){
e.preventDefault(); // prevents page reloading
socket.emit('chat message', $('#contexto').val()+'|'+$('#nome').val()+'|'+$('#quantidade').val());
$('#m').val('');
return false;
});
socket.on('chat message', function(msg){
$('#messages').append('<li>'+msg+'</li>');
$("html, body").animate({ scrollTop: $(document).height() }, 1000);
});
});
</script>