-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
61 lines (50 loc) · 1.73 KB
/
scripts.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
/*=============== SHOW MENU ===============*/
const navMenu = document.getElementById('nav-menu'),
navToggle = document.getElementById('nav-toggle'),
navClose = document.getElementById('nav-close');
/*===== MENU SHOW =====*/
// Validate if constant exists
if (navToggle) {
navToggle.addEventListener('click', () => {
navMenu.classList.toggle('show-menu');
});
}
/*===== MENU HIDDEN =====*/
// Validate if constant exists
if (navClose) {
navClose.addEventListener('click', () => {
navMenu.classList.remove('show-menu');
});
}
/*===== ACTIVE AND REMOVE MENU =====*/
const navLink = document.querySelectorAll('.nav-link');
function linkAction() {
/*Active link*/
navLink.forEach((n) => n.classList.remove('active'));
this.classList.add('active');
/*Remove menu mobile*/
const navMenu = document.getElementById('nav-menu');
navMenu.classList.remove('show');
}
navLink.forEach((n) => n.addEventListener('click', linkAction));
/*===== CONTACT-TEXTAREA =====*/
let textArea = document.getElementById('textbox');
let characterCounter = document.getElementById('char_count');
const maxNumOfChars = 100;
const countCharacters = () => {
let numOfEnteredChars = textArea.value.length;
let counter = maxNumOfChars - numOfEnteredChars;
characterCounter.textContent = counter + '/100';
if (counter < 0) {
characterCounter.style.color = 'var(--ninth-color)';
} else if (counter < 20) {
characterCounter.style.color = 'var(--fifteenth-color)';
} else {
characterCounter.style.color = 'var(--second-color)';
}
};
textArea.addEventListener('input', countCharacters);
// let toggle = document.querySelector('.nav-toggle');
// toggle.addEventListener('click', function () {
// toggle.classList.toggle('is-active');
// });