-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
272 lines (246 loc) · 8.24 KB
/
script.js
File metadata and controls
272 lines (246 loc) · 8.24 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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
window.onload = () => {
onScroll();
hamburgerClickHandler();
hamburgerOnBlur();
phoneClickHandler();
phoneSliderHandler();
portfolioTagsHandler();
portfolioImgClickHandler();
formButtonClickHandler();
}
// Hamburger MENU
const hamburger = document.querySelector('.hamburger')
const hamburger__menu = document.querySelector('.hamburger__menu')
const header__wrapper = document.querySelector('.header__wrapper')
let position = true
const hamburgerClickHandler = () => {
hamburger.addEventListener('click', function() {
rotateMenu()
menuOpen()
menuClose()
})
}
const hamburgerOnBlur = () => {
hamburger__menu.addEventListener('click', function() {
menuOnBlur()
})
}
const rotateMenu = () => {
if(position) {
hamburger.classList.remove('rotate-reverse')
hamburger.classList.add('rotate')
position = false
}
else {
hamburger.classList.remove('rotate')
hamburger.classList.add('rotate-reverse')
position = true
}
}
const menuClose = () => {
if(position) {
header__wrapper.style.borderBottomColor = '#323746';
hamburger__menu.classList.add('hidden')
document.body.classList.remove('overflow-hidden')
}
}
const menuOpen = () => {
if (!position) {
header__wrapper.style.borderBottomColor = '#2d303a';
hamburger__menu.classList.remove('hidden')
document.body.classList.add('overflow-hidden')
}
}
const menuOnBlur = () => {
rotateMenu();
menuClose();
}
// Navigation
const onScroll = () => {
document.addEventListener('scroll', event => {
const currentPosition = window.scrollY + 95
const sections = document.querySelectorAll('.wrapper>section')
const links = document.querySelectorAll('#navigation a')
sections.forEach(el => {
if(el.offsetTop <= currentPosition && (el.offsetTop + el.offsetHeight) >= currentPosition ) {
links.forEach(item => {
item.classList.remove('active')
if(el.getAttribute('id') === item.getAttribute('href').substring(1))
item.classList.add('active')
})
}
})
}
)}
// PhonesScreen
const slider = document.querySelector('.slider');
const verticalScreen = document.querySelector('.screen-vertical');
const horizontalScreen = document.querySelector('.screen-horizontal');
const phones = document.querySelectorAll('.phones');
const phoneClickHandler = () => {
let hiddenVertical = false;
let hiddenHorizontal = false;
slider.addEventListener('click', (el) => {
if(el.target.classList.contains('screen-vertical') ||
el.target.classList.contains ('vertical-phone')) {
if(!hiddenVertical) {
verticalScreenRemove();
hiddenVertical = true;
} else {
verticalScreenAdd();
hiddenVertical = false;
}
}
if(el.target.classList.contains('screen-horizontal') ||
el.target.classList.contains ('horizontal-phone')) {
if(!hiddenHorizontal) {
horizontalScreenRemove();
hiddenHorizontal = true;
} else {
horizontalScreenAdd();
hiddenHorizontal = false;
}
}
})
}
const verticalScreenRemove = () => {
verticalScreen.classList.add('hidden')
}
const verticalScreenAdd = () => {
verticalScreen.classList.remove('hidden')
}
const horizontalScreenRemove = () => {
horizontalScreen.classList.add('hidden')
}
const horizontalScreenAdd = () => {
horizontalScreen.classList.remove('hidden')
}
// Phones SLider
const phoneSliderHandler = () => {
slider.addEventListener('click', el => {
if(el.target.classList.contains('slider__chev-left')) {
if(isEnabled) {
nextPhone(currentPhone)
}
}
if(el.target.classList.contains('slider__chev-right')) {
if(isEnabled) {
prevPhone(currentPhone)
}
}
})
}
let currentPhone = 0;
let isEnabled = true;
function changeCurrentPhone(n) {
currentPhone = (n + phones.length) % phones.length;
}
function hideItem(direction) {
isEnabled = false;
phones[currentPhone].classList.add(direction);
phones[currentPhone].addEventListener('animationend', function() {
this.classList.remove('active-slide', direction);
});
}
function showItem(direction) {
phones[currentPhone].classList.add('active-slide-next', direction);
phones[currentPhone].addEventListener('animationend', function() {
this.classList.remove('active-slide-next', direction);
this.classList.add('active-slide');
isEnabled = true;
});
}
function nextPhone(n) {
hideItem('to-left');
changeCurrentPhone(n + 1);
showItem('from-right');
}
function prevPhone(n) {
hideItem('to-right');
changeCurrentPhone(n - 1);
showItem('from-left');
}
// Portfolio
const gallery = document.querySelector('.portfolio__gallery');
const gallery_item = document.querySelectorAll('.portfolio__gallery-item');
const portfolioNavigation = document.querySelector('.portfolio__navigation');
const portfolioNavigationTab = document.querySelectorAll('.portfolio__navigation-item');
const portfolioImgClickHandler = () => {
gallery.addEventListener('click', event => {
if(event.target.hasAttribute('alt')){
imgRemoveBorder()
event.target.classList.add('active-img')
}
})
}
const imgRemoveBorder = () => {
gallery.querySelectorAll('img').forEach(el=>el.classList.remove('active-img'))
}
const portfolioTagsHandler = () => {
portfolioNavigation.addEventListener('click', event => {
if(event.target.classList.contains('portfolio__navigation-item')) {
removeActivePortfolioNavigation();
imgRemoveBorder();
event.target.classList.add('active-tab');
changeGallery();
}
})
}
const removeActivePortfolioNavigation = () => {
portfolioNavigationTab.forEach(el=> el.classList.remove('active-tab'))
}
const changeGallery = () => {
let arrImages = [];
gallery_item.forEach(el => arrImages.push(el) )
arrImages.sort(()=>Math.random()-0.5)
gallery.append(...arrImages)
}
// Form modal window
const open_button = document.getElementById('open-button');
const close_button = document.getElementById('close-button');
const modal_window = document.getElementById('message-block');
const formButtonClickHandler = () => {
openModalWindow();
closeModalWindow();
}
const openModalWindow = () => {
open_button.addEventListener('click', (event) => {
const form_name = document.getElementById('name').value.toString();
const form_email = document.getElementById('email').value.toString();
const form_subject = document.getElementById('subject').value.toString();
const form_describe = document.getElementById('describe').value.toString();
let modal_name = document.getElementById('name-result');
let modal_email = document.getElementById('email-result');
let modal_subject = document.getElementById('subject-result');
let modal_describe = document.getElementById('describe-result');
modal_window.style.top = pageYOffset + 'px'
modal_name.innerText = `Отправитель: ${form_name}`;
modal_email.innerText = `Эл. Адрес: ${form_email}`;
if(form_subject){
modal_subject.innerText = `Тема: ${form_subject}`;
} else {
modal_subject.innerText = 'Без темы'
}
if(form_describe){
modal_describe.innerText = `Описание: ${form_describe}`;
} else {
modal_describe.innerText = 'Без описания'
}
if(form_name && form_email) {
modal_window.classList.remove('hidden')
document.body.classList.add('overflow-hidden')
event.preventDefault()
}
})
}
const reset_form = () => {
let form = document.getElementById('form')
form.reset();
}
const closeModalWindow = () => {
close_button.addEventListener('click', ()=> {
reset_form()
modal_window.classList.add('hidden')
document.body.classList.remove('overflow-hidden')
})
}