-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat.html
49 lines (43 loc) · 2.03 KB
/
chat.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap demo</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<style>
form {background: rgba(0, 0, 0, 0.082); padding: 0.25rem; position: fixed; border-style: groove; bottom:0; left: 0; right: 0; display: flex; height:3rem; box-sizing: border-box; backdrop-filter: blur(10px); }
ul > li:nth-child(odd){background: #2bff0083;text-align: right; font-style: arial; font-weight: 500;}
</style>
</head>
<div>
<ul class="list.group"></ul>
<form action="">
<input type="text" class="form-control" placeholder="Ingrese el mensaje">
<button type="buttom" class="btn btn-primary">Enviar</button>
</form>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script src="http://localhost:8080/socket.io/socket.io.js"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.5.3/socket.io.js"></script> -->
<script>
let socket = io()
//referencias elementos DOM
const form = document.querySelector('form')
const input = document.querySelector('input')
let mensajes = document.querySelector('ul')
form.addEventListener('submit',(e)=>{
e.preventDefault()
if(input.value){
socket.emit('chat',input.value)
input.value =''
}
})
socket.on('chat',(msg)=>{
let item = document.createElement('li')
item.textContent = msg
mensajes.appendChild(item)
window.scrollTo(0,document.body.scrollHeight)
})
</script>
</div>
</html>