-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·370 lines (334 loc) · 11.4 KB
/
index.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
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
//for setting the language profieciency bar in whatwedocontainer
for(let i=0; i<document.getElementsByClassName('fluency').length; i++){
let elem = document.getElementsByClassName('fluency')[i];
let fluency = elem.dataset.fluency;
elem.style.width = (fluency/100)*65 + "%";
elem.style.right = 5 + (65 - ((fluency/100)*65)) + "%";
//console.log(elem.style.width);
}
var currentScreen = 1;
function addClassTo(screenClassList){
console.log(screenClassList);
//console.log(Object.keys(screenClass).length);
for(let x=1; x<=Object.keys(screenClassList).length; x++){ //iterates for every element of screenclass['show' or 'hide']
let screenClass = screenClassList[x];
let classArray = screenClass[0],
classToAdd = screenClass[1],
add = screenClass[2],
addTimes = screenClass[3];
//console.log(classArray);
//addTimes array contains the time difference from the beginning of the function call to the time when the class is added
if(addTimes.length == 1){
classArray.forEach(function(){
addTimes.push(addTimes[0]);
})
addTimes.pop();
}
//if classarray has only element that means evbery that element will be added to classlist of every classArray elem
if(classToAdd.length == 1){
classArray.forEach(function(){
classToAdd.push(classToAdd[0]);
})
classToAdd.pop(); //because classarray already had one element in it was passed to the func
}
let i = 0;
for(let i=0; i<classArray.length; i++){
let elems = document.querySelectorAll(classArray[i]);
for(let ii=0; ii<elems.length; ii++){
if(add){
//console.log('adding ' + classToAdd[i] + ' to ' + classArray[i]);
setTimeout(function(){
elems[ii].classList.add(classToAdd[i]);
}, addTimes[i])
}else if(!add){
setTimeout(function(){
elems[ii].classList.remove(classToAdd[i]);
}, addTimes[i])
}
}
}
}
}
var screenClasses = {
1: { 'show': { 1: [ ['.blackBack', '.whiteBack', '.hello', '.from', '.rubberband'],
['blackBackVisible', 'whiteBackVisible', 'helloVisible', 'fromVisible', 'rubberbandVisible'],
true,
[0] ],
2: [ ['.whatWeDoContainer > .headline'],
['visible'],
false,
[100] ],
3: [ ['.whatWeDoContainer > .headline'],
['hidden'],
true,
[100] ] } ,
'hide': { 1: [ ['.blackBack', '.whiteBack', '.hello', '.from', '.rubberband'],
['blackBackVisible', 'whiteBackVisible', 'helloVisible', 'fromVisible', 'rubberbandVisible'],
false,
[0] ] } },
2: { 'show': { 1: [ ['.whatWeDoContainer'],
['wwdVisible'],
true,
[0] ],
2: [ ['.whatWeDoContainer > .headline', '.primary .title', '.skill', '.features .box', '.skillset .title', '.secondary .title'],
['hidden'],
false,
[0] ],
3: [ ['.BLACK','.headline > div'],
['DO','do'],
true,
[0,100] ],
4: [ ['.whatWeDoContainer > .headline', '.primary .title', '.skill', '.features .box', '.skillset .title', '.secondary .title'],
['visible'],
true,
[80, 250, 370, 400, 450, 500] ] },
'hide': { 1: [ ['.primary .title', '.skill', '.features .box', '.skillset .title', '.secondary .title'],
['visible'],
false,
[100, 300, 500, 700, 900] ],
2: [ ['.primary .title', '.skill', '.features .box', '.skillset .title', '.secondary .title'],
['hidden'],
true,
[0] ],
3: [ ['.BLACK'],
['DO'],
false,
[0] ] } },
3: { 'show': { 1: [ ['.whatWeDidContainer'],
['wwdVisible'],
true,
[0] ],
2: [ ['.category', '.category img', '.category > .title', '.projects'],
['hidden'],
false,
[0] ],
3: [ ['.BLACK','.headline > div'],
['DID','did'],
true,
[0,100] ],
4: [ [ '.category', '.category img', '.category > .title', '.projects'],
['visible'],
true,
[100, 300, 500, 700] ] },
'hide': { 1: [ ['.BLACK','.headline > div'],
['DID','did'],
false,
[0, 100] ],
2: [ ['.category', '.category img', '.category > .title', '.projects'],
['visible'],
false,
[100, 300, 500, 700] ],
3: [ [ '.category', '.category img', '.category > .title', '.projects'],
['hidden'],
true,
[0] ] } },
4: { 'show': { 1: [ ['.BLACK','.headline div'],
['ARE','are'],
true,
[0,200] ],
2: [ ['.whatWeAreContainer'],
['wwdVisible'],
true,
[0] ],
3: [ ['.dev', '.dev .dp', '.dev .name', '.dev .bio'],
['visible'],
true,
[100,200,300,400] ] },
'hide': { 1: [ ['.dev', '.dev .dp', '.dev .name', '.dev .bio'],
['visible'],
false,
[100,200,300,400] ],
2: [ ['.BLACK','.headline div'],
['ARE','are'],
false,
[0, 200] ] } },
5: { 'show': { 1: [ ['.BLACK','.contact_us_container'],
['CONTACT','wwdVisible'],
true,
[0,0] ],
2: [ ['.contact_us > .title', '.contact_us .email', '.contact_us .message', 'contact_us .submit', '.contact_us_container .padder', '.contact_us_container .submit'],
['visible'],
true,
[200] ],
3: [ ['.whatWeDoContainer > .headline'],
['visible'],
false,
[0] ],
4: [ ['.whatWeDoContainer > .headline'],
['hidden'],
true,
[0] ],
3: [ ['.headline div'],
['are'],
true,
[200] ] } ,
'hide': { 1: [ ['.contact_us > .title', '.contact_us .email', '.contact_us .message', 'contact_us .submit', '.contact_us_container .padder' , '.contact_us_container .submit'],
['visible'],
false,
[200] ],
2: [ ['.whatWeDoContainer > .headline'],
['visible'],
true,
[700] ],
3: [ ['.BLACK','.whatWeDoContainer > .headline'],
['CONTACT','hidden'],
false,
[300,700] ],
4: [ ['.contact_us_container'],
['wwdVisible'],
false,
[340] ] } }
}
document.addEventListener('DOMContentLoaded', function(){
///////////entry screen animations
setTimeout(function(){
//addClassTo(['.blackBack', '.whiteBack', '.hello', '.from'], ['blackBackVisible', 'whiteBackVisible', 'helloVisible', 'fromVisible'], true, [0]);
addClassTo(screenClasses[1]['show']);
}, 100);
})
var currentScreen = 1, lastScreen = 1; //the first screen is screen 1
var scrolling = false;
var direction = true; //true means downward scroll
var BLACK = document.getElementsByClassName('BLACK')[0];
document.addEventListener('wheel', function(e){
if(!scrolling){
console.log("detected" + e.deltaY);
//checks if the user is scrolling up or down
if(e.deltaY >= 0){
scrolling = true;
direction = true;
}else if(e.deltaY <= 0){
scrolling = true;
direction = false;
}
scroll(direction);
}
})
document.addEventListener('scroll', function(){
console.log("scrolled");
})
if(getPlatformType() == 'Mobile'){
}
function scroll(direction){
if(direction == true){
currentScreen++;
if(lastScreen == 1){
document.querySelector('.whatWeDoContainer > .headline').style.display = 'flex';
//BLACK.style.width = 70 + 'vw';
addClassTo(screenClasses[1]['hide']);
setTimeout(function(){
addClassTo(screenClasses[2]['show']);
}, 500);
}else if(lastScreen == 2){
//BLACK.style.width = 50 + 'vw';
addClassTo(screenClasses[2]['hide']);
document.querySelector('.headline div').classList.add('do');
setTimeout(function(){
addClassTo(screenClasses[3]['show']);
}, 500)
}else if(lastScreen == 3){
addClassTo(screenClasses[3]['hide']);
//this next timeout is important for the scrolling of headline
setTimeout(function(){
document.querySelector('.headline div').classList.add('did');
}, 102);
setTimeout(function(){
addClassTo(screenClasses[4]['show']);
}, 500);
}else if(lastScreen == 4){
document.querySelector('.whatWeDoContainer > .headline').style.display = 'none';
addClassTo(screenClasses[4]['hide']);
//setTimeout(function(){BLACK.style.width = 20 + 'vw';}, 300);
setTimeout(function(){
addClassTo(screenClasses[5]['show']);
}, 400);
}
//cancels the extra scroll events in case the user scrolls again before the animation completes
setTimeout(function(){
scrolling = false;
lastScreen = currentScreen;
}, 500);
//cancels out the extra scroll after the last screen of the full page
if(currentScreen > 5){
scrolling = false;
currentScreen = 5;
}
}else if(direction == false){
currentScreen--;
console.log("backward and " + lastScreen);
if(lastScreen == 2){
document.querySelector('.whatWeDoContainer > .headline').style.display = 'none';
addClassTo(screenClasses[2]['hide']);
//BLACK.style.width = 50 + 'vw';
setTimeout(function(){
addClassTo(screenClasses[1]['show']);
}, 500);
}else if(lastScreen == 3){
addClassTo(screenClasses[3]['hide']);
//BLACK.style.width = 70 + 'vw';
setTimeout(function(){
addClassTo(screenClasses[2]['show']);
}, 500);
}else if(lastScreen == 4){
addClassTo(screenClasses[4]['hide']);
setTimeout(function(){
addClassTo(screenClasses[3]['show']);
}, 500);
}else if(lastScreen == 5){
document.querySelector('.whatWeDoContainer > .headline').style.display = 'flex';
addClassTo(screenClasses[5]['hide']);
//setTimeout(function(){BLACK.style.width = 50 + 'vw'}, 300);
setTimeout(function(){
addClassTo(screenClasses[4]['show']);
}, 800);
}
setTimeout(function(){
scrolling = false;
lastScreen = currentScreen;
}, 500);
if(currentScreen < 0){
scrolling = false;
currentScreen = 0;
}
}
}
function getPlatformType() {
if(navigator.userAgent.match(/mobile/i)) {
return 'Mobile';
} else if (navigator.userAgent.match(/iPad|Android|Touch/i)) {
return 'Tablet';
} else {
return 'Desktop';
}
}
var touchsurface = document.getElementsByTagName('body')[0],
startX,
startY,
dist,
threshold = 150, //required min distance traveled to be considered swipe
allowedTime = 200, // maximum time allowed to travel that distance
elapsedTime,
startTime
touchsurface.addEventListener('touchstart', function(e){
//touchsurface.innerHTML = ''
var touchobj = e.changedTouches[0]
dist = 0
startX = touchobj.screenX
startY = touchobj.screenY
startTime = new Date().getTime() // record time when finger first makes contact with surface
e.preventDefault()
}, false)
touchsurface.addEventListener('touchmove', function(e){
e.preventDefault() // prevent scrolling when inside DIV
}, false)
touchsurface.addEventListener('touchend', function(e){
var touchobj = e.changedTouches[0]
dist = touchobj.screenY - startY // get total dist traveled by finger while in contact with surface
elapsedTime = new Date().getTime() - startTime // get time elapsed
// check that elapsed time is within specified, horizontal dist traveled >= threshold, and vertical dist traveled <= 100
if(elapsedTime >= 150 && Math.abs(dist) >= 30){
(dist > 0) ? direction = 0 : direction = 1;
scroll(direction);
}
e.preventDefault()
}, false)