-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
141 lines (109 loc) · 4.58 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//Carousel Welcome
var copy = document.querySelector(".placard-content").cloneNode(true);
document.querySelector(".placard").appendChild(copy);
//Caousel Feedback
document.getElementById("next").addEventListener("click", function() {
const carousel = document.querySelector(".fb-content");
const itemWidth = carousel.querySelector(".fb-comment").offsetWidth + parseInt(getComputedStyle(carousel).gap);
const totalWidth = carousel.scrollWidth;
const scrollPosition = carousel.scrollLeft;
const itemsToScroll = window.innerWidth < 700 ? 1 : 2;
if (scrollPosition + itemWidth * itemsToScroll < totalWidth) {
carousel.scrollBy({ left: itemWidth * itemsToScroll, behavior: 'smooth' });
}
updateArrowStates();
});
document.getElementById("prev").addEventListener("click", function() {
const carousel = document.querySelector(".fb-content");
const itemWidth = carousel.querySelector(".fb-comment").offsetWidth + parseInt(getComputedStyle(carousel).gap);
const scrollPosition = carousel.scrollLeft;
const itemsToScroll = window.innerWidth < 700 ? 1 : 2;
if (scrollPosition > 0) {
carousel.scrollBy({ left: -itemWidth * itemsToScroll, behavior: 'smooth' });
}
updateArrowStates();
});
function updateArrowStates() {
const carousel = document.querySelector(".fb-content");
const scrollPosition = carousel.scrollLeft;
const itemWidth = carousel.querySelector(".fb-comment").offsetWidth + parseInt(getComputedStyle(carousel).gap);
const totalWidth = carousel.scrollWidth;
const itemsToScroll = window.innerWidth < 700 ? 1 : 2;
if (scrollPosition + itemWidth * itemsToScroll >= totalWidth) {
document.getElementById("next").classList.add("disabled");
} else {
document.getElementById("next").classList.remove("disabled");
}
if (scrollPosition === 0) {
document.getElementById("prev").classList.add("disabled");
} else {
document.getElementById("prev").classList.remove("disabled");
}
}
window.addEventListener("load", updateArrowStates);
document.querySelector(".fb-content").addEventListener("scroll", function() {
updateArrowStates();
});
//Accordion FAQ
document.addEventListener("DOMContentLoaded", () => {
const faqItems = document.querySelectorAll(".faq-item");
faqItems.forEach(item => {
const header = item.querySelector(".faq-header");
const content = item.querySelector(".faq-ls-descp");
header.addEventListener("click", () => {
faqItems.forEach(otherItem => {
if (otherItem !== item) {
const otherContent = otherItem.querySelector(".faq-ls-descp");
otherItem.classList.remove("open");
otherContent.style.maxHeight = null;
}
});
if (item.classList.contains("open")) {
item.classList.remove("open");
content.style.maxHeight = null; // Fecha
} else {
item.classList.add("open");
content.style.maxHeight = content.scrollHeight + "px";
}
});
});
});
//Header Scroll
const header = document.getElementById('header');
let lastScrollY = window.scrollY;
window.addEventListener('scroll', () => {
const currentScrollY = window.scrollY;
if (currentScrollY > 0) {
header.style.top = '0';
} else {
header.style.top = '-80px';
}
lastScrollY = currentScrollY;
});
//Menu Mobile
document.addEventListener('DOMContentLoaded', function () {
const btnMobile = document.getElementById('menu-mobile');
const offScreenMenu = document.querySelector('.off-screen-menu');
const btnWelcome = document.getElementById('menu-mobile-welcome');
const body = document.body;
btnMobile.addEventListener('click', function () {
offScreenMenu.classList.toggle('active');
body.classList.toggle('no-scroll');
});
btnWelcome.addEventListener('click', function () {
offScreenMenu.classList.toggle('active');
body.classList.toggle('no-scroll');
});
const closeButton = document.getElementById('btn-mobile');
closeButton.addEventListener('click', function () {
offScreenMenu.classList.remove('active');
body.classList.remove('no-scroll');
});
const menuItems = document.querySelectorAll('.of-nav-menu');
menuItems.forEach(item => {
item.addEventListener('click', function () {
offScreenMenu.classList.remove('active');
body.classList.remove('no-scroll');
});
});
});