-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
337 lines (305 loc) · 11.6 KB
/
app.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
var scaleFun
// shim layer with setTimeout fallback
window.reqAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 1000 / 60)
}
})()
var leftBarElem, fixedLeftBarElem, rightBarElem
setTimeout(function(){
var elem2 = document.querySelector('.iv-2')
var elem3 = document.querySelector('.iv-3')
var elem4 = document.querySelector('.iv-4')
var elem5 = document.querySelector('.iv-5')
var elem6 = document.querySelector('.iv-6')
var elem7 = document.querySelector('.iv-7')
fixedLeftBarElem = document.querySelector('.left-bar')
leftBarElem = document.querySelector('.left-bar.abs')
rightBarElem = document.querySelector('.right-bar-since')
leftBarElem.style.height = `${window.innerHeight}px`
fixedLeftBarElem.style.height = `${window.innerHeight}px`
elem4.style.height = `${window.innerHeight}px`
elem5.style.height = `${window.innerHeight}px`
elem6.style.height = `${window.innerHeight}px`
elem2.style.top = `${window.innerHeight}px`
elem3.style.top = `${window.innerHeight+elem2.offsetHeight}px`
elem3.style.height = `${window.innerHeight}px`
elem7.style.height = `${window.innerHeight}px`
elem7.style.top = `${window.innerHeight+elem2.offsetHeight+elem3.offsetHeight}px`
elem4.style.top = `${window.innerHeight+elem2.offsetHeight+elem3.offsetHeight+elem7.offsetHeight}px`
elem5.style.top = `${window.innerHeight+elem2.offsetHeight+elem3.offsetHeight+elem4.offsetHeight+elem7.offsetHeight}px`
elem6.style.top = `${window.innerHeight+elem2.offsetHeight+elem3.offsetHeight+elem4.offsetHeight+elem7.offsetHeight+elem5.offsetHeight}px`
document.querySelector('.experties .recog-content').style.top = `${window.innerHeight/9}px`
document.querySelector('.recog .recog-content').style.top = `${window.innerHeight/6}px`
registerListeners()
}, 500 )
setTimeout(function(){
document.querySelector('.main-h1-1-dumb').style.background = 'transparent'
document.querySelector('.main-h1-2-dumb').style.background = 'transparent'
document.querySelector('.main-h1-3-dumb').style.background = 'transparent'
document.querySelector('.main-h1-1').style.background = 'transparent'
document.querySelector('.main-h1-2').style.background = 'transparent'
document.querySelector('.main-h1-3').style.background = 'transparent'
document.querySelector('.prfl-img').classList.add('active')
},1000)
function fixSec(sec) {
var elem = document.querySelector(sec)
elem.style.position = 'fixed'
return elem
}
function absSec(sec) {
var elem = document.querySelector(sec)
elem.style.position = 'absolute'
return elem
}
function initSec1(){
var sec1InView = new Waypoint.Inview({
element: document.querySelector(".iv-1"),
enter: function(direction) {
console.log('sec-1 Enter triggered with direction ' + direction)
},
entered: function(direction) {
console.log('sec-1 Entered triggered with direction ' + direction)
},
exit: function(direction) {
console.log('sec-1 Exit triggered with direction ' + direction)
},
exited: function(direction) {
console.log('sec-1 exited...')
}
})
}
function initSec2(){
var sec2InView = new Waypoint.Inview({
element: document.querySelector(".iv-2"),
enter: function(direction) {
console.log('sec-2 Enter triggered with direction ' + direction)
if (direction === 'down') {
fixSec('.iv-1')
}
},
entered: function(direction) {
console.log('sec-2 Entered triggered with direction ' + direction)
if(direction === 'up') {
leftBarElem.style.position = 'absolute'
rightBarElem.style.position = 'absolute'
fixedLeftBarElem.classList.remove('black')
fixedLeftBarElem.style.position = 'fixed'
}
},
exit: function(direction) {
console.log('sec-2 Exit triggered with direction ' + direction)
leftBarElem.style.position = 'fixed'
rightBarElem.style.position = 'fixed'
fixedLeftBarElem.classList.add('black')
fixedLeftBarElem.style.position = 'sticky'
},
exited: function(direction) {
console.log('sec-2 exited...')
if(direction === 'up') {
absSec('.iv-1').style.top = `0px`
}
}
})
}
function initSec3(){
document.querySelector('.case-study-btn.herman').addEventListener('click', function() {
openHermanCaseStudy('.herm-right-panel')
}, false);
document.querySelector('.right-panel-back').addEventListener('click', function(){
closeHermanCaseStudy('.herm-right-panel')
})
var sec3InView = new Waypoint.Inview({
element: document.querySelector(".iv-3"),
enter: function(direction) {
if(direction === 'down') {
fixSec('.iv-2').style.top = `${((document.querySelector('.iv-2').offsetHeight) * -1) + window.innerHeight}px`
scaleImage()
}
},
exited: function(direction) {
if(direction === 'up') {
absSec('.iv-2').style.top = `${document.querySelector('.iv-1').offsetHeight}px`
}
}
})
}
function initSec7() {
var sec7InView = new Waypoint.Inview({
element: document.querySelector(".iv-7"),
enter: function(direction) {
if (direction === 'down') {
fixSec('.iv-3').style.top = `${((document.querySelector('.iv-3').offsetHeight) * -1) + window.innerHeight}px`
document.querySelector('.sec-3-head-content').classList.add('active')
scaleImage('.herm-chair.compass-img', '.sec-3-head-content.comp')
}
},
entered: function(direction) {
console.log('sec-7 Entered triggered with direction ' + direction)
if(direction === 'up') {
leftBarElem.style.position = 'absolute'
rightBarElem.style.position = 'absolute'
fixedLeftBarElem.classList.remove('black')
fixedLeftBarElem.style.position = 'fixed'
}
},
exit: function(direction) {
console.log('sec-7 Exit triggered with direction ' + direction)
leftBarElem.style.position = 'fixed'
rightBarElem.style.position = 'fixed'
fixedLeftBarElem.classList.add('black')
fixedLeftBarElem.style.position = 'sticky'
},
exited: function(direction) {
if(direction === 'up') {
var elem1 = document.querySelector('.iv-1')
var elem2 = document.querySelector('.iv-2')
absSec('.iv-3').style.top = `${elem2.offsetHeight+(elem1.offsetHeight)}px`
}
}
})
}
function initSec4(){
var sec4InView = new Waypoint.Inview({
element: document.querySelector(".iv-4"),
enter: function(direction) {
if(direction === 'down') {
fixSec('.iv-7').style.top = `${((document.querySelector('.iv-7').offsetHeight) * -1) + window.innerHeight}px`
}
},
exited: function(direction) {
console.log('sec-4 exited...')
if(direction === 'up') {
var elem1 = document.querySelector('.iv-1')
var elem2 = document.querySelector('.iv-2')
var elem3 = document.querySelector('.iv-3')
absSec('.iv-7').style.top = `${elem3.offsetHeight+elem2.offsetHeight+(elem1.offsetHeight)}px`
}
}
})
}
function initSec5(){
var sec5InView = new Waypoint.Inview({
element: document.querySelector(".iv-5"),
enter: function(direction) {
if(direction === 'down') {
fixSec('.iv-4').style.top = `${((document.querySelector('.iv-4').offsetHeight) * -1) + window.innerHeight}px`
}
},
exited: function(direction) {
console.log('sec-5 exited...')
if(direction === 'up') {
var elem1 = document.querySelector('.iv-1')
var elem2 = document.querySelector('.iv-2')
var elem3 = document.querySelector('.iv-3')
var elem7 = document.querySelector('.iv-7')
absSec('.iv-4').style.top = `${elem7.offsetHeight+elem3.offsetHeight+elem2.offsetHeight+(elem1.offsetHeight)}px`
}
}
})
}
function initSec6() {
var sec6InView = new Waypoint.Inview({
element: document.querySelector(".iv-6"),
enter: function(direction) {
console.log('sec-6 Enter triggered with direction ' + direction)
if(direction === 'down') {
fixSec('.iv-5').style.top = `${((document.querySelector('.iv-5').offsetHeight) * -1) + window.innerHeight}px`
}
},
entered: function(direction) {
console.log('sec-6 Entered triggered with direction ' + direction)
},
exit: function(direction) {
console.log('sec-6 Exit triggered with direction ' + direction)
},
exited: function(direction) {
console.log('sec-6 exited...')
if(direction === 'up') {
var elem1 = document.querySelector('.iv-1')
var elem2 = document.querySelector('.iv-2')
var elem3 = document.querySelector('.iv-3')
var elem7 = document.querySelector('.iv-7')
var elem4 = document.querySelector('.iv-4')
absSec('.iv-5').style.top = `${elem4.offsetHeight+elem7.offsetHeight+elem3.offsetHeight+elem2.offsetHeight+(elem1.offsetHeight)}px`
}
}
})
}
function registerListeners() {
initSec1()
initSec2()
initSec3()
initSec7()
initSec4()
initSec5()
initSec6()
}
var caseBody
function openHermanCaseStudy(selector) {
document.querySelector(selector).classList.add('active')
setTimeout(function(){
// document.querySelectorAll('.b-logo').forEach(function(elem){
// elem.classList.add('hide')
// })
// document.querySelector('.b-down').classList.add('hide')
document.querySelector('body').classList.add('stuck')
if (!caseBody) {
caseBody = new Waypoint.Inview({
element: document.querySelector(".dummy-case-trigger"),
enter: function(direction) {
console.log('case-body Enter triggered with direction ' + direction)
},
entered: function(direction) {
console.log('case-body Entered triggered with direction ' + direction)
},
exit: function(direction) {
console.log('case-body Exit triggered with direction ' + direction)
},
exited: function(direction) {
console.log('case-body exited...')
}
})
}
}, 500)
}
function closeHermanCaseStudy(selector) {
document.querySelector(selector).classList.remove('active')
setTimeout(function(){
document.querySelectorAll('.b-logo').forEach(function(elem){
elem.classList.remove('hide')
})
// document.querySelector('.b-down').classList.remove('hide')
document.querySelector('body').classList.remove('stuck')
}, 500)
}
function runOnScroll (elem, startScrollPos, height, activeClass) {
return function(){
reqAnimFrame(()=>{
var scrollPos = window.pageYOffset
var endScroll = startScrollPos + height
if (scrollPos <= endScroll) {
var perPixelVal = (1.5 / height)
var pixelsScrolled = endScroll - scrollPos
var scaleVal = 1 + (pixelsScrolled * perPixelVal)
elem.style.transform = 'scale('+scaleVal+')'
} else {
window.removeEventListener('scroll', scaleFun)
var actClass = activeClass || '.sec-3-head-content'
document.querySelector(actClass).classList.add('active')
}
})
}
}
function scaleImage (selector, activeClass) {
window.removeEventListener('scroll', scaleFun)
var startScrollPos = window.pageYOffset
var height = window.innerHeight
var selec = selector || '.herm-chair'
var elem = document.querySelector(selec)
scaleFun = runOnScroll(elem, startScrollPos, height, activeClass)
window.addEventListener("scroll", scaleFun, false)
}