-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSuperCarsJS.js
209 lines (181 loc) · 5.67 KB
/
SuperCarsJS.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
// Select both scrolling elements
const scrolling = document.querySelector('.scrolling');
const scrolling2 = document.querySelector('.scrolling2');
const faders = document.querySelectorAll('.fade-in');
const sliders = document.querySelectorAll('.from-bottom');
const navLinks = document.querySelectorAll('.nav-link');
const home = document.getElementById('Home');
const about = document.querySelector('#About');
const bugatti = document.getElementById('Bugatti');
const lambo = document.getElementById('lambo');
const mcl = document.getElementById('McL');
const support = document.getElementById('support');
const homeLink = document.querySelector('.home');
const aboutLink = document.querySelector('.about');
const bugattiLink = document.querySelector('.bugatti');
const lamboLink = document.querySelector('.lambo');
const mclLink = document.querySelector('.mcl');
const quoteLink = document.querySelector('.quote2');
const supportLink = document.querySelector('.support');
const sec1 = document.querySelector('.section1');
const sec2 = document.querySelector('.section2');
const sec3 = document.querySelector('.section3');
const sec4 = document.querySelector('.section4');
const sec5 = document.querySelector('.section5');
const sec6 = document.querySelector('.section6');
const sec7 = document.querySelector('.section7');
// Update Navbar ----------------------------------------------------------------------
// ObserverOptions
const homeObserverOptions = {
rootMargin: "-50% 0px 0px 0px",
threshold: .25
};
const aboutObserverOptions = {
rootMargin: "-50% 0px 0px 0px",
threshold: .25
};
const bugattiObserverOptions = {
rootMargin: "-50% 0px 0px 0px",
threshold: .1
};
const lamboObserverOptions = {
rootMargin: "-50% 0px 0px 0px",
threshold: .25
};
const mclObserverOptions = {
rootMargin: "-50% 0px 0px 0px",
threshold: .2
};
const quoteObserverOptions = {
rootMargin: "-50% 0px 0px 0px",
threshold: .2
};
const supportObserverOptions = {
rootMargin: "-30% 0px 0px 0px",
threshold: .3
};
// Home section
const homeObserver = new IntersectionObserver(function(entries, homeObserverOptions) {
entries.forEach(entry => {
if(!entry.isIntersecting) {
homeLink.classList.remove("active");
} else {
homeLink.classList.add("active");
}
});
}, homeObserverOptions);
// About section
const aboutObserver = new IntersectionObserver(function(entries, homeObserverOptions) {
entries.forEach(entry => {
if(!entry.isIntersecting) {
aboutLink.classList.remove("active");
} else {
aboutLink.classList.add("active");
}
});
}, aboutObserverOptions);
// Bugatti section
const bugattiObserver = new IntersectionObserver(function(entries, homeObserverOptions) {
entries.forEach(entry => {
if(!entry.isIntersecting) {
bugattiLink.classList.remove("active");
} else {
bugattiLink.classList.add("active");
}
});
}, bugattiObserverOptions);
// Lambo section
const lamboObserver = new IntersectionObserver(function(entries, homeObserverOptions) {
entries.forEach(entry => {
if(!entry.isIntersecting) {
lamboLink.classList.remove("active");
} else {
lamboLink.classList.add("active");
}
});
}, lamboObserverOptions);
// McL section
const mclObserver = new IntersectionObserver(function(entries, homeObserverOptions) {
entries.forEach(entry => {
if(!entry.isIntersecting) {
mclLink.classList.remove("active");
} else {
mclLink.classList.add("active");
}
});
}, mclObserverOptions);
// Quote section
const quoteObserver = new IntersectionObserver(function(entries, homeObserverOptions) {
entries.forEach(entry => {
if(!entry.isIntersecting) {
quoteLink.classList.remove("active");
} else {
quoteLink.classList.add("active");
}
});
}, quoteObserverOptions);
// Home section
const supportObserver = new IntersectionObserver(function(entries, homeObserverOptions) {
entries.forEach(entry => {
if(!entry.isIntersecting) {
supportLink.classList.remove("active");
} else {
supportLink.classList.add("active");
}
});
}, supportObserverOptions);
homeObserver.observe(sec1);
aboutObserver.observe(sec2);
bugattiObserver.observe(sec3);
lamboObserver.observe(sec4);
mclObserver.observe(sec5);
quoteObserver.observe(sec6);
supportObserver.observe(sec7);
// ------------------------------------------------------------------------------------
// This sets the range that is needed for observing.
// Threshold being 1 makes it only work when the full element is in the viewport
// Root margin can also be used here.
const beginScrollOptions = {
threshold: 0
};
// Function to Insert class name when in range
const beginScroll = new IntersectionObserver
(function(entries, beginScroll) {
entries.forEach(entry => {
if (!entry.isIntersecting) {
return;
} else {
entry.target.classList.add('scrollAnimation');
scrolling2.classList.add('scrollAnimation2')
// beginScroll.unobserve(entry.target);
}
})
}, beginScrollOptions);
beginScroll.observe(scrolling);
const appearOptions = {
threshold: 0,
rootMargin: '0px 0px -300px 0px'
};
// Insert fade in class
const appearOnScroll = new IntersectionObserver (function(entries, appearOnScroll) {
entries.forEach(entry => {
if (!entry.isIntersecting) {
return;
} else {
entry.target.classList.add('appear');
appearOnScroll.unobserve(entry.target);
}
});
},
appearOptions);
faders.forEach(fader => {
appearOnScroll.observe(fader);
});
sliders.forEach(slider => {
appearOnScroll.observe(slider);
});
// To add active state when nav bar links clicked
$(".nav-link").on("click", function(){
$(".nav-link.active").removeClass("active");
$(this).addClass("active");
});