-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
231 lines (214 loc) · 6.55 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
const nav = document.querySelector('.nav__list');
const navItems = document.querySelectorAll('.nav__item');
const burgerBtn = document.querySelector('.nav__burger-btn');
const counterContainer = document.querySelector('.about__counter');
const teamButtons = document.querySelectorAll('.about-team__button');
const teamPictures = document.querySelectorAll('.about-team__pic');
const projectButtons = document.querySelectorAll('.projects__button');
const projectPictures = document.querySelectorAll('.projects__pic');
const opinionContents = document.querySelectorAll('.opinion__content');
const opinionPrevButton = document.querySelector('.fa-chevron-left');
const opinionNextButton = document.querySelector('.fa-chevron-right');
const logoContainer = document.querySelector('.clients__container');
const clientsLogos = document.querySelectorAll('.clients__logo');
const accordionBtns = document.querySelectorAll('.accordion__button');
const inputEmailButton = document.querySelector('.footer__input-btn');
const sections = document.querySelectorAll('section');
const options = {
rootMargin: '-25px',
};
const scrollSpyOptions = {
rootMargin: '-300px',
};
let index = 0;
let countOne;
let countTwo;
let countThree;
const handleNav = () => {
burgerAnimation();
menuLinkAnimation();
nav.classList.toggle('nav__active');
document.body.classList.toggle('overflow-hidden');
};
const burgerAnimation = () => {
const burgerBar = document.querySelectorAll('.nav__burger-bar');
burgerBar[0].classList.toggle('nav__burger-bar--rotate-first');
burgerBar[1].classList.toggle('nav__burger-bar--hide');
burgerBar[2].classList.toggle('nav__burger-bar--rotate-second');
};
const menuLinkAnimation = () => {
navItems.forEach((navItem) => {
navItem.classList.toggle('nav__active');
});
};
const hideMenu = () => {
navItems.forEach((navItem) => {
navItem.classList.toggle('nav__active');
});
document.body.classList.remove('overflow-hidden');
nav.classList.toggle('nav__active');
burgerAnimation();
};
const counter = () => {
let numOne;
numOne = 0;
let numTwo;
numTwo = 0;
let numThree;
numThree = 0;
const counterNum = document.querySelectorAll('.about__counter-number');
counterNum[0].textContent = numOne;
counterNum[1].textContent = numTwo;
counterNum[2].textContent = numThree;
countOne = setInterval(function () {
if (numOne < 26) {
numOne++;
counterNum[0].textContent = numOne;
}
}, 70);
countTwo = setInterval(function () {
if (numTwo < 58) {
numTwo++;
counterNum[1].textContent = numTwo;
}
}, 70);
countThree = setInterval(function () {
if (numThree < 76) {
numThree++;
counterNum[2].textContent = numThree;
}
}, 70);
};
const startCounter = (entry) => {
if (entry[0].isIntersecting) {
clearInterval(countOne);
clearInterval(countTwo);
clearInterval(countThree);
counter();
}
};
const startLogoSlider = (entry) => {
if (entry[0].isIntersecting) {
logoContainer.classList.add('slider-animation');
}
};
const changeGallery = (e) => {
let text = e.target.textContent.toLowerCase();
projectButtons.forEach((btn) => {
if (btn === e.target) {
btn.classList.add('active__button');
} else {
btn.classList.remove('active__button');
}
});
projectPictures.forEach((picture) => {
if (picture.classList.contains(text)) {
picture.classList.replace('hidden', 'on-view');
} else {
picture.classList.replace('on-view', 'hidden');
}
});
};
const changeTeamGallery = (e) => {
let text = e.target.textContent.toLowerCase();
teamButtons.forEach((btn) => {
if (btn === e.target) {
btn.classList.add('active__button');
} else {
btn.classList.remove('active__button');
}
});
teamPictures.forEach((picture) => {
if (picture.classList.contains(text)) {
picture.classList.replace('hidden', 'on-view');
} else {
picture.classList.replace('on-view', 'hidden');
}
});
};
const hideOpinion = () => {
opinionContents.forEach((content) => {
if (content.classList.contains('on-view')) {
content.classList.replace('on-view', 'hidden');
}
});
};
const changeOpinion = () => {
opinionContents[index].classList.replace('hidden', 'on-view');
opinionContents[index + 1].classList.replace('hidden', 'on-view');
};
const nextOpinion = () => {
if (index > opinionContents.length - 3) {
index = 0;
hideOpinion();
} else if (index >= 0) {
index = index + 2;
hideOpinion();
}
changeOpinion();
};
const prevOpinion = () => {
if (index === 0) {
index = opinionContents.length - 2;
hideOpinion();
} else if (index < opinionContents.length - 1) {
index = index - 2;
hideOpinion();
}
changeOpinion();
};
burgerBtn.addEventListener('click', handleNav);
navItems.forEach((el) => {
el.addEventListener('click', hideMenu);
});
projectButtons.forEach((btn) => {
btn.addEventListener('click', changeGallery);
});
teamButtons.forEach((btn) => {
btn.addEventListener('click', changeTeamGallery);
});
opinionNextButton.addEventListener('click', nextOpinion);
opinionPrevButton.addEventListener('click', prevOpinion);
const showPanel = function () {
const accordionPanel = this.nextElementSibling;
this.firstElementChild.classList.toggle('rotate');
accordionPanel.classList.toggle('show');
accordionPanel.firstElementChild.classList.toggle('show-txt');
};
const mailValidation = () => {
const mailInput = document.querySelector('.footer__input-mail');
let regex = new RegExp('[a-z0-9]+@[a-z]+.[a-z]{2,3}');
console.log(mailInput.value);
if (mailInput.value.match(regex)) {
console.log('dobrze');
} else {
console.log('chujowo');
}
};
accordionBtns.forEach((el) => {
el.addEventListener('click', showPanel);
});
inputEmailButton.addEventListener('click', mailValidation);
const observerCounter = new IntersectionObserver(startCounter, options);
observerCounter.observe(counterContainer);
const observerLogoSlider = new IntersectionObserver(startLogoSlider, options);
observerLogoSlider.observe(logoContainer);
const scrollSpy = (entries) => {
for (const entry of entries) {
if (entry.isIntersecting) {
for (let i = 0; i < navItems.length; i++) {
if (entry.target === sections[i - 1] && i > 0) {
console.log(entry.target);
console.log(i);
navItems[i].classList.add('nav__desktop-active');
} else {
navItems[i].classList.remove('nav__desktop-active');
}
}
}
}
};
const observer = new IntersectionObserver(scrollSpy, scrollSpyOptions);
sections.forEach((section) => {
observer.observe(section);
});