-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscript.js
More file actions
218 lines (201 loc) · 6.47 KB
/
script.js
File metadata and controls
218 lines (201 loc) · 6.47 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
// script.js
// start document
$(document).ready(function(){
// initialize variables
var menuActive = false;
var sponsorHeight = $('#s-sponsor').outerHeight();
var partnerHeight = $('#s-partner').outerHeight();
var faqHeight = $('#s-faq').outerHeight();
var scheduleHeight = $('#s-schedule').outerHeight();
var aboutHeight = $('#s-about').outerHeight() + $('#s-numbers').outerHeight();
var navHeight = $('#nav').outerHeight();
var coverHeight = $('#s-banner').outerHeight() - navHeight;
var docWidth = $('#nav').width();
var breakpoint = 860;
// smooth scroll
$(function() {
$('a[href*=#]').click(function() {
if (location.pathname.replace(/^\//,'') === this.pathname.replace(/^\//,'') && location.hostname === this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - navHeight
}, 1000);
return false;
}
}
});
});
// navbar animations
function animateNavBar(w) {
if ($('#nav').width() >= breakpoint) {
// animate colors if non-mobile
if (w.scrollTop() > 1) {
// bg-color
$('#nav').css({'background-color':'#FFFCF9'});
// link-style
$('#nav a').addClass('nav-scroll');
$('#nav a').removeClass('nav-top');
// menu button color
$('.st0').css({'fill':'#F2AE6A'});
$('.st0').css({'stroke':'#F2AE6A'});
// logo style
$('.logo-b').show();
$('.logo-w').hide();
} else {
// bg-color
$('#nav').css({'background-color':'transparent'});
// link-style
$('#nav a').removeClass('nav-scroll');
$('#nav a').addClass('nav-top');
// menu button color
$('.st0').css({'fill':'#FFFFFF'});
$('.st0').css({'stroke':'#FFFFFF'});
// logo style
$('.logo-w').show();
$('.logo-b').hide();
}
} else {
// otherwise set colors if mobile
$('#nav').css({'background-color':'#FFFCF9'});
$('#nav a').addClass('nav-scroll');
$('#nav a').removeClass('nav-top');
$('.st0').css({'fill':'#F2AE6A'});
$('.st0').css({'stroke':'#F2AE6A'});
$('.logo-b').show();
$('.logo-w').hide();
}
}
// update DOM elements
function updateProperties() {
// update heights for scroll navigation
sponsorHeight = $('#s-sponsor').outerHeight();
partnerHeight = $('#s-partner').outerHeight();
faqHeight = $('#s-faq').outerHeight();
scheduleHeight = $('#s-schedule').outerHeight();
aboutHeight = $('#s-about').outerHeight() + $('#s-numbers').outerHeight();
navHeight = $('#nav').outerHeight();
coverHeight = $('#s-banner').outerHeight() - navHeight;
// update width for pseudo-mobile check
docWidth = $('#nav').width();
}
// toggle menu
function toggleMenu() {
if (menuActive) {
// hide menu if shown
$('#nav-menu').css({'display':'none'});
menuActive = false;
} else {
// show menu if hidden
$('#nav-menu').css({'display':'flex'});
menuActive = true;
}
}
// click actions
function clickActions() {
//// menu
// toggle menu on menu button click
$('.nav-mini').click(function() {
toggleMenu();
});
// update document width
updateProperties();
// toggle menu on navigation
$('.nav-link').click(function() {
if (docWidth < breakpoint) {
toggleMenu();
}
});
// toggle menu on click-away
$('section').click(function() {
if (docWidth < breakpoint) {
if (menuActive) {
toggleMenu();
}
}
});
//// faq
$('.faq-group').click(function() {
if ($('p', this).css('display') === 'none') {
$('p', this).css({'display': 'block'});
$('p', this).css({'opacity': '1'});
} else {
$('p', this).css({'display': 'none'});
$('p', this).css({'opacity': '0'});
}
});
}
// init methods
animateNavBar($(window));
updateProperties();
clickActions();
// on resize
$(window).resize(function() {
// update size-dependent properties
updateProperties();
// animate nav bar
animateNavBar($(window));
// normalize initial menu status
if (docWidth >= breakpoint) {
menuActive = false;
toggleMenu();
} else {
menuActive = true;
toggleMenu();
}
});
// on scroll
$(window).scroll(function() {
// update scroll-dependent properties
updateProperties();
// animate nav bar
animateNavBar($(window));
// change cover image
if ($(this).scrollTop() < coverHeight + 5) {
$('#s-cover').addClass('s-cover1');
$('#s-cover').removeClass('s-cover2');
} else {
$('#s-cover').removeClass('s-cover1');
$('#s-cover').addClass('s-cover2');
}
// update nav bar links
if ($(this).scrollTop() >= faqHeight + scheduleHeight + aboutHeight + coverHeight + partnerHeight) {
$('a[href="/#about"]').removeClass('selected');
$('a[href="/#schedule"]').removeClass('selected');
$('a[href="/#faq"]').removeClass('selected');
$('a[href="/#partner"]').removeClass('selected');
$('a[href="/#sponsor"]').addClass('selected');
} else if ($(this).scrollTop() >= faqHeight + scheduleHeight + aboutHeight + coverHeight) {
$('a[href="/#about"]').removeClass('selected');
$('a[href="/#schedule"]').removeClass('selected');
$('a[href="/#faq"]').removeClass('selected');
$('a[href="/#partner"]').addClass('selected');
$('a[href="/#sponsor"]').removeClass('selected');
} else if ($(this).scrollTop() >= scheduleHeight + aboutHeight + coverHeight) {
$('a[href="/#about"]').removeClass('selected');
$('a[href="/#schedule"]').removeClass('selected');
$('a[href="/#faq"]').addClass('selected');
$('a[href="/#partner"]').removeClass('selected');
$('a[href="/#sponsor"]').removeClass('selected');
} else if ($(this).scrollTop() >= aboutHeight + coverHeight) {
$('a[href="/#about"]').removeClass('selected');
$('a[href="/#schedule"]').addClass('selected');
$('a[href="/#faq"]').removeClass('selected');
$('a[href="/#partner"]').removeClass('selected');
$('a[href="/#sponsor"]').removeClass('selected');
} else if ($(this).scrollTop() >= coverHeight) {
$('a[href="/#about"]').addClass('selected');
$('a[href="/#schedule"]').removeClass('selected');
$('a[href="/#faq"]').removeClass('selected');
$('a[href="/#partner"]').removeClass('selected');
$('a[href="/#sponsor"]').removeClass('selected');
} else {
$('a[href="/#about"]').removeClass('selected');
$('a[href="/#schedule"]').removeClass('selected');
$('a[href="/#faq"]').removeClass('selected');
$('a[href="/#partner"]').removeClass('selected');
$('a[href="/#sponsor"]').removeClass('selected');
}
});
});