-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
67 lines (54 loc) · 1.71 KB
/
script.js
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
const menu = document.querySelector('#menu-icon')
const navbar = document.querySelector('.navbar')
const chatButton = document.querySelector('#chat-button')
const chatBox = document.querySelector('#chat-box')
const chatInput = document.querySelector('#chat-input')
const chatContent = document.querySelector('#chat-content')
const sendButton = document.querySelector('#send-button')
chatButton.addEventListener('click', function () {
if (chatBox.style.display === 'none') {
chatBox.style.display = 'block'
} else {
chatBox.style.display = 'none'
}
})
chatInput.addEventListener('keypress', function (e) {
if (e.key === 'Enter') {
appendMessage(chatInput.value)
chatInput.value = ''
}
})
sendButton.addEventListener('click', function () {
appendMessage(chatInput.value)
chatInput.value = ''
})
document.addEventListener('click', function (event) {
const isClickInside = chatBox.contains(event.target)
const isClickOnButton = chatButton.contains(event.target)
if (!isClickInside && !isClickOnButton && chatBox.style.display === 'block') chatBox.style.display = 'none'
})
menu.onclick = () => {
toggleMenu(!menu.classList.contains('bx-x'))
}
window.onscroll = () => {
toggleMenu(false)
}
document.querySelectorAll('.footer i').forEach(icon => {
icon.addEventListener('click', function () {
open(this.children[0].href, '_blank')
})
})
function appendMessage(inputValue) {
const message = document.createElement('p')
message.textContent = inputValue
chatContent.appendChild(message)
}
function toggleMenu(active) {
if (active) {
menu.classList.add('bx-x')
navbar.classList.add('active')
} else {
menu.classList.remove('bx-x')
navbar.classList.remove('active')
}
}