-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
83 lines (69 loc) · 2.87 KB
/
main.js
File metadata and controls
83 lines (69 loc) · 2.87 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
document.addEventListener('DOMContentLoaded', () => {
const btnMonthly = document.getElementById('btn-monthly');
const btnAnnual = document.getElementById('btn-annual');
const prices = document.querySelectorAll('.plan-price');
const periods = document.querySelectorAll('.plan-period');
const descriptions = document.querySelectorAll('.plan-description');
const btnsGetStarted = document.querySelectorAll('.btn-get-started');
const setActive = (isAnnual) => {
prices.forEach((price) => {
const newPrice = isAnnual ? price.dataset.annual : price.dataset.monthly;
price.classList.remove('price-show');
price.classList.add('price-hide');
setTimeout(() => {
price.textContent = `$${newPrice}`;
price.classList.remove('price-hide');
price.classList.add('price-show');
}, 150);
});
periods.forEach((period) => {
period.textContent = isAnnual ? 'per year' : 'per month';
});
if (isAnnual) {
btnAnnual.classList.add('bg-gray-900', 'text-white', 'font-semibold');
btnMonthly.classList.remove('bg-gray-900', 'text-white', 'font-semibold');
} else {
btnMonthly.classList.add('bg-gray-900', 'text-white', 'font-semibold');
btnAnnual.classList.remove('bg-gray-900', 'text-white', 'font-semibold');
}
descriptions.forEach(desc => {
desc.textContent = isAnnual ? desc.dataset.annual : desc.dataset.monthly;
});
btnsGetStarted.forEach(btn => {
btn.textContent = isAnnual ? btn.dataset.annual : btn.dataset.monthly;
});
};
if (btnMonthly && btnAnnual) {
btnMonthly.addEventListener('click', () => setActive(false));
btnAnnual.addEventListener('click', () => setActive(true));
}
const btnMenu = document.getElementById("btn-menu");
const mobileMenu = document.getElementById("mobile-menu");
if (btnMenu && mobileMenu) {
const iconOpen = document.getElementById("icon-open");
const iconClose = document.getElementById("icon-close");
btnMenu.addEventListener("click", (e) => {
e.stopPropagation();
const isOpen = mobileMenu.classList.toggle("show-menu");
btnMenu.setAttribute("aria-expanded", isOpen);
iconOpen.classList.toggle("hidden", isOpen);
iconClose.classList.toggle("hidden", !isOpen);
});
document.addEventListener("click", (e) => {
if (!mobileMenu.contains(e.target) && !btnMenu.contains(e.target)) {
mobileMenu.classList.remove("show-menu");
btnMenu.setAttribute("aria-expanded", "false");
iconOpen.classList.remove("hidden");
iconClose.classList.add("hidden");
}
});
document.addEventListener("keydown", (e) => {
if (e.key === "Escape") {
mobileMenu.classList.remove("show-menu");
btnMenu.setAttribute("aria-expanded", "false");
iconOpen.classList.remove("hidden");
iconClose.classList.add("hidden");
}
});
}
});