-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
218 lines (180 loc) · 7.09 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
const MENU = document.getElementById('menu')
const BUTTON = document.getElementById('btn')
const CLOSE_BUTTON = document.getElementById('close-btn')
const IMAGES = document.getElementById('imgs')
const TABS = document.getElementById ('tabs')
//MENU
MENU.addEventListener('click', (event) => {
MENU.querySelectorAll('a').forEach(el => el.classList.remove('active'));
event.target.classList.add('active');
})
//FORM
document.querySelector('.form1').addEventListener('submit', (event) => {
event.preventDefault();
if(document.querySelector('.form1').checkValidity()){
const subject = document.getElementById('subject').value;
const describe = document.getElementById('describe').value;
(subject=="") ? document.getElementById('result-subject').innerText='Без темы': document.getElementById('result-subject').innerText = 'Тема: '+subject;
(describe=="") ? document.getElementById('result-describe').innerText='Без описания': document.getElementById('result-describe').innerText = 'Описание: '+describe;
document.getElementById('message-block').classList.remove('hidden');
}
document.querySelector('.form1').reset();
})
CLOSE_BUTTON.addEventListener('click', () => {
document.getElementById('message-block').classList.add('hidden');
})
//BORDER IMAGE
IMAGES.addEventListener('click', (event) => {
IMAGES.querySelectorAll('img').forEach(el => el.classList.remove('border'));
let target=event.target;
if (target.tagName != 'IMG') return;
if (target.classList.contains('border')) {
target.classList.remove('border')
}
console.log(target);
})
IMAGES.addEventListener('click', (event) => {
IMAGES.querySelectorAll('img').forEach(el => el.classList.remove('border'));
let target=event.target;
if (target.tagName != 'IMG') return;
target.classList.add('border');
}
)
//ACTIVE TABS AND RANDOM IMAGE
TABS.addEventListener('click', (event) => {
TABS.querySelectorAll('p').forEach(el => el.classList.remove('box-shadow-tabs'));
let target=event.target;
if (target.tagName != 'P') return
target.classList.add('box-shadow-tabs');
})
TABS.addEventListener('click', (event) => {
const ARRAY_IMAGES = [...document.getElementById('imgs').querySelectorAll('li')].sort(function compareRandom(a, b) {
return Math.random() - 0.5;
});
if (event.target.tagName != 'P') return
IMAGES.innerHTML;
IMAGES.append(...ARRAY_IMAGES);
});
//SLIDER
let items = document.querySelectorAll('.slider .slide');
let currentItem = 0;
let isEnabled = true;
function changeCurrentItem(n) {
currentItem = (n + items.length) % items.length;
}
function hideItem(direction) {
isEnabled = false;
items[currentItem].classList.add(direction);
items[currentItem].addEventListener('animationend', function() {
this.classList.remove('active', direction);
});
}
function showItem(direction) {
items[currentItem].classList.add('next', direction);
items[currentItem].addEventListener('animationend', function() {
this.classList.remove('next', direction);
this.classList.add('active');
isEnabled = true;
});
}
function nextItem(n) {
hideItem('to-left');
changeCurrentItem(n + 1);
showItem('from-right');
}
function previousItem(n) {
hideItem('to-right');
changeCurrentItem(n - 1);
showItem('from-left');
}
document.querySelector('.control.left').addEventListener('click', function() {
if (isEnabled) {
previousItem(currentItem);
}
});
document.querySelector('.control.right').addEventListener('click', function() {
if (isEnabled) {
nextItem(currentItem);
}
});
//OFF LAYER
document.getElementById('layer1').addEventListener('click', (event) => {
event.target.classList.add('hide-layer');
})
document.getElementById('base1').addEventListener('click', (event) => {
document.getElementById('layer1').classList.remove('hide-layer');
})
document.getElementById('layer2').addEventListener('click', (event) => {
event.target.classList.add('hide-layer');
})
document.getElementById('base2').addEventListener('click', (event) => {
document.getElementById('layer2').classList.remove('hide-layer');
})
//MENU SCROLL
window.addEventListener('scroll', function() {
if(window.pageYOffset>0) {
MENU.querySelectorAll('li').forEach(el => el.classList.remove('active'));
MENU.querySelector('.home').classList.add('active');
}
if(window.pageYOffset>500) {
MENU.querySelectorAll('li').forEach(el => el.classList.remove('active'));
MENU.querySelector('.services').classList.add('active');
}
if(window.pageYOffset>1100) {
MENU.querySelectorAll('li').forEach(el => el.classList.remove('active'));
MENU.querySelector('.portfolio').classList.add('active');
}
if(window.pageYOffset>2000) {
MENU.querySelectorAll('li').forEach(el => el.classList.remove('active'));
MENU.querySelector('.about').classList.add('active');
}
if(window.pageYOffset>2550) {
MENU.querySelectorAll('li').forEach(el => el.classList.remove('active'));
MENU.querySelector('.contact').classList.add('active');
}
});
const anchors = document.querySelectorAll('a[href*="#"]')
for (let anchor of anchors) {
anchor.addEventListener('click', function (e) {
e.preventDefault()
const blockID = anchor.getAttribute('href');
document.getElementById(blockID.replace(/^#/,'')).scrollIntoView({
behavior: 'smooth',
block: 'start'
})
})
//MENU MOBILE
document.querySelector('.for-mobile-menu').addEventListener('click', (event)=> {
if (MENU.classList.contains('hidden-menu')) {
MENU.classList.remove('hidden-menu');
document.getElementById('message-block').classList.remove('hidden')
document.getElementById('message').classList.add('hidden')
}
else {
MENU.classList.add('hidden-menu');
document.getElementById('message-block').classList.add('hidden')
}
})
MENU.querySelector('.home').addEventListener('click', (event) => {
if(document.body.clientWidth<767)
MENU.classList.add('hidden-menu');
document.getElementById('message-block').classList.add('hidden')
})
MENU.querySelector('.services').addEventListener('click', (event) => {
if(document.body.clientWidth<767)
MENU.classList.add('hidden-menu');
document.getElementById('message-block').classList.add('hidden')
})
MENU.querySelector('.portfolio').addEventListener('click', (event) => {
if(document.body.clientWidth<767) MENU.classList.add('hidden-menu');
document.getElementById('message-block').classList.add('hidden')
})
MENU.querySelector('.about').addEventListener('click', (event) => {
if(document.body.clientWidth<767) MENU.classList.add('hidden-menu');
document.getElementById('message-block').classList.add('hidden')
})
MENU.querySelector('.contact').addEventListener('click', (event) => {
if(document.body.clientWidth<767) MENU.classList.add('hidden-menu');
document.getElementById('message-block').classList.add('hidden')
})
}