-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.js
182 lines (115 loc) · 3.92 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
var slideIndex = 1;
showSlides(slideIndex);
// Next/previous controls
function plusSlides(n) {
showSlides(slideIndex += n);
}
// Thumbnail image controls
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("slide");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slides[slideIndex-1].style.display = "grid";
}
const spaceship = document.querySelector(".spaceship");
let previousPlanet , currentPlanet;
function viewFacts(id){
currentPlanet = document.getElementById(id);
// viewing planet details
document.getElementById("planetData").style.display = "block";
if(previousPlanet){
previousPlanet.classList.add("hidden");
}
currentPlanet.classList.remove("hidden");
currentPlanet.scrollIntoView();
scrollAnimation(currentPlanet);
previousPlanet = currentPlanet;
}
function scrollAnimation(planet){
// intersection observer - onscroll animation
const facts = planet.querySelectorAll(".facts");
// animation on facts
const appearOptions = {
threshold:0.5,
rootMargin : "0px 0px 50px 0px"
}
const appearOnScroll = new IntersectionObserver( function(entries ,appearOnScroll ){
entries.forEach( entry => {
if(!entry.isIntersecting){
return;
}else{
entry.target.classList.add("slideUp");
appearOnScroll.unobserve(entry.target);
}
})
} , appearOptions);
facts.forEach( fact =>{
appearOnScroll.observe(fact);
});
}
// animation on navbar
const navbar = document.querySelector("nav");
const header = document.querySelector("header");
const options = {
rootMargin : "-200px"
}
const linksObserver = new IntersectionObserver( function(entries , linksObserver ){
entries.forEach( entry =>{
if(!entry.isIntersecting){
navbar.style.backgroundColor = "#000";
}else{
navbar.style.backgroundColor = "transparent";
}
});
}, options);
linksObserver.observe(header);
// close side panel
let sidePanel = document.getElementById("solarSideCard");
function closeSidePanel(){
sidePanel.style.right = "-100%";
}
// open side panel
let infoPanelPrevious, infoPanelCurrent;
infoPanelPrevious = document.getElementById('sideInfoSun');
function openSidePanel(id){
infoPanelCurrent = document.getElementById(id);
sidePanel.style.right="0";
infoPanelPrevious.classList.add('hidden');
infoPanelCurrent.classList.remove('hidden');
infoPanelPrevious = infoPanelCurrent;
}
// move to planet carousel
function moveToPlanetCarousel(){
document.getElementById('planet-carousel').scrollIntoView();
}
// reset dropdown
function resetDropdown(){
document.querySelector("details").removeAttribute('open');
}
// mobile menu
let hamburgerMenu = document.getElementById('hamburgerMenu');
let mobileMenu = document.getElementById('mobileMenu');
function showMobileMenu(){
hamburgerMenu.classList.toggle('active');
mobileMenu.classList.toggle('active');
setTimeout(()=>{
mobileMenu.querySelector('.top-section').classList.toggle('active');
mobileMenu.querySelector('.bottom-section').classList.toggle('active');
},300);
}
// reset mobile menu
function resetMobileMenu(){
if(mobileMenu.classList.contains("active")){
hamburgerMenu.classList.remove('active');
mobileMenu.classList.remove('active');
mobileMenu.querySelector('.top-section').classList.remove('active');
mobileMenu.querySelector('.bottom-section').classList.remove('active');
}
}