-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
83 lines (70 loc) · 2.39 KB
/
script.js
File metadata and controls
83 lines (70 loc) · 2.39 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const $ = (selector) => document.querySelector(selector);
const $$ = (selector) => document.querySelectorAll(selector);
const $header = $('.header');
const $navItems = $$('.header__nav a');
const $toggleMenu = $('#toggle-menu');
const $overlay = $('.overlay');
const $aboutBtns = $$('.about__description--btn');
const $aboutTexts = $$('.about__description--text');
const $languageToggle = $('.language-toggle');
const $languageDropdown = $('.language-dropdown');
const $languageOptions = $$('.language-option');
const toggleMenu = () => {
$toggleMenu.checked = !$toggleMenu.checked;
};
const toggleAbout = (index) => {
$aboutBtns.forEach((btn, i) => {
btn.classList.remove('active');
if (i === index) {
btn.classList.add('active');
}
});
$aboutTexts.forEach((text, i) => {
text.classList.add('hidden');
if (i === index) {
text.classList.remove('hidden');
}
});
};
$navItems.forEach((item) => {
item.addEventListener('click', toggleMenu);
});
$overlay.addEventListener('click', toggleMenu);
$aboutBtns.forEach((btn, i) => {
btn.addEventListener('click', () => toggleAbout(i));
});
document.addEventListener("scroll", (event) => {
if (window.scrollY > 0) {
$header.style.backgroundColor = '#ffffff';
$header.style.color = 'var(--color-tertiary)';
$header.style.boxShadow = '0 0 8px rgba(0, 0, 0, 0.5)';
$('.header .toggle').style.color = 'var(--color-tertiary)';
return;
}
$header.style.backgroundColor = 'transparent';
$header.style.color = '#ffffff';
$header.style.boxShadow = 'none';
$('.header .toggle').style.color = '#ffffff';
})
$languageToggle.addEventListener('click', function() {
$languageDropdown.classList.toggle('active');
});
$languageOptions.forEach(option => {
option.addEventListener('click', function() {
$languageOptions.forEach(opt => opt.classList.remove('active'));
this.classList.add('active');
$languageToggle.textContent = this.textContent.slice(0, 2).toUpperCase();
$languageDropdown.classList.remove('active');
const selectedLang = this.getAttribute('data-lang');
if(selectedLang === 'es') {
window.location.href = '/es';
} else {
window.location.href = '/';
}
});
});
document.addEventListener('click', function(event) {
if (!$languageDropdown.contains(event.target) && !$languageToggle.contains(event.target)) {
$languageDropdown.classList.remove('active');
}
});