-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathVisualization.vue
223 lines (216 loc) · 8.22 KB
/
Visualization.vue
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
<template>
<div id="visualization">
<Splash />
<Intro
v-if="checkIfSplashIsRendered"
/>
<Chapter
v-if="checkIfSplashIsRendered"
id="chapter2"
image="chapter5"
alt="An image of a greenish-blue river winding through a snowy forest, faded into the background to serve as a backdrop for the section title."
:height="50"
>
<template #chapterTitle>
From Winter Snow to Spring Flow
</template>
</Chapter>
<KeyDynamics />
<DiagramsNormal
v-if="checkIfSplashIsRendered"
id="diagrams-normal"
/>
<DiagramsHigh
v-if="checkIfSplashIsRendered"
id="diagrams-good"
/>
<DiagramsLow
v-if="checkIfSplashIsRendered"
id="diagrams-bad"
/>
<Chapter
v-if="checkIfSplashIsRendered"
id="chapter1"
image="chapter4"
alt="An image of snowpack with wind-swept ripples on top, faded into the background to serve as a backdrop for the section title."
:height="50"
>
<template #chapterTitle>
Measuring Snowpack
</template>
</Chapter>
<MeasuringSWE v-if="checkIfSplashIsRendered" />
<SWE v-if="checkIfSplashIsRendered" />
<!-- <Chapter
v-if="checkIfSplashIsRendered"
id="chapter2-3"
image="chapter9"
alt="An landscape of snowy mountain tops with pine trees in the valley and a bright blue sky overhead, faded into the background to serve as a backdrop for the section title."
:height="50"
>
<template v-slot:chapterTitle>
Changes in snowmelt have downstream consequences
</template>
</Chapter> -->
<SWEanim v-if="checkIfSplashIsRendered" />
<Chapter
v-if="checkIfSplashIsRendered"
id="chapterLast"
image="chapter11"
alt="An image of two bighorn sheep looking at each other standing in snow with a bright green lake of meltwater behind them. The image is faded into the background to serve as a backdrop for the section title."
:height="50"
>
<template #chapterTitle>
Snowmelt season has already begun
</template>
</Chapter>
<SNTLMap v-if="checkIfSplashIsRendered" />
<Chapter
v-if="checkIfSplashIsRendered"
id="chapterLast"
image="chapter15"
alt="An image of a mossy mountaintop with fog rising over the peaks and small patches of snow melting into the green ground. The image is faded into the background to serve as a backdrop for the section title."
:height="50"
>
<template #chapterTitle>
Learn More
</template>
</Chapter>
<References v-if="checkIfSplashIsRendered" />
<Methods v-if="checkIfSplashIsRendered" />
</div>
</template>
<script>
import { ScrollToPlugin } from "gsap/ScrollToPlugin"; // to trigger scroll events
import { ScrollTrigger } from "gsap/ScrollTrigger"; // animated scroll events
export default {
name: 'Visualization',
components: {
Splash: () => import( /* webpackPreload: true */ /*webpackChunkName: "section"*/ "./../components/Splash"),
Intro: () => import( /* webpackPrefetch: true */ /*webpackChunkName: "Intro"*/ "./../components/Intro"),
SNTLMap: () => import( /*webpackChunkName: "SNTLMap"*/ "./../components/SNTLmap"),
SWE: () => import( /*webpackChunkName: "SWE"*/ "./../components/SWE"),
SWEanim: () => import( /* webpackPrefetch: true */ /*webpackChunkName: "SWE"*/ "./../components/SWEanim"),
MeasuringSWE: () => import( /* webpackPrefetch: true */ /*webpackChunkName: "SWE"*/ "./../components/MeasuringSWE"),
KeyDynamics: () => import( /* webpackPrefetch: true */ /*webpackChunkName: "keydynamics"*/ "./../components/KeyDynamics"),
DiagramsNormal: () => import( /* webpackPrefetch: true */ /*webpackChunkName: "diagrams"*/ "./../components/DiagramsNormal"),
DiagramsHigh: () => import( /* webpackPrefetch: true */ /*webpackChunkName: "diagrams"*/ "./../components/DiagramsHigh"),
DiagramsLow: () => import( /* webpackPrefetch: true */ /*webpackChunkName: "diagrams"*/ "./../components/DiagramsLow"),
References: () => import( /*webpackChunkName: "References"*/ "./../components/References"),
Methods: () => import( /*webpackChunkName: "References"*/ "./../components/Methods"),
Chapter: () => import( /* webpackPrefetch: true */ /*webpackChunkName: "ChapterTitles"*/ "./../components/SectionTitle"),
},
computed: {
checkIfSplashIsRendered() {
return this.$store.state.splashRenderedOnInitialLoad;
}
},
mounted(){
const self = this;
//Waits until the first DOM paint is complete
//Allows us to only run the functionality when we know the DOM elements are loaded
this.$gsap.registerPlugin(ScrollToPlugin, ScrollTrigger); // register gsap plugins for scrollTrigger
this.$nextTick(function() {
this.parallaxScroll();
});
//Wait for page to load then run this function
window.addEventListener("load", function(){
self.findCarouselContainers();
});
},
updated(){
this.lazyLoadImages();
},
methods:{
parallaxScroll(){
this.$gsap.utils.toArray(".parallax").forEach((chapter, i) => {
chapter.bg = chapter.querySelector(".bg");
this.$gsap.to(chapter.bg, {
ease: "none",
scrollTrigger: {
trigger: chapter,
start: "bottom bottom",
scrub: true,
toggleActions: "restart pause reverse pause"
},
yPercent: 50,
})
})
},
lazyLoadImages(){
const loadImg = function(entries, observer){
entries.forEach(entry => {
if(entry.isIntersecting){
//Get first source element
entry.target.srcset = entry.target.dataset.srcset;
//Get second source element
entry.target.nextElementSibling.srcset = entry.target.dataset.srcset;
const findImg = entry.target.parentElement.querySelector("img");
findImg.addEventListener('load', function () {
entry.target.parentElement.classList.remove('lazy');
});
observer.unobserve(entry.target);
}
});
}
const imgTargets = document.querySelectorAll(".lazy > source");
const imgObserver = new window.IntersectionObserver(loadImg, {
//Watch entire viewport
root: null,
threshold: 0,
rootMargin: "300px"
})
imgTargets.forEach(img => {
imgObserver.observe(img)
});
},
findCarouselContainers(){
let self = this;
const carouselContainers = document.querySelectorAll(".carouselContainer");
carouselContainers.forEach(function(container){
container.addEventListener("click", self.addFooterCaption);
});
},
//Carousel full size image captions
addFooterCaption(e){
const self = this;
const imgContainer = document.querySelector(".fullscreen-v-img");
const title = document.querySelector(".title-v-img");
const img = document.querySelector(".content-v-img img");
//Mutation observer
//If img src changes, update caption
const observer = new MutationObserver((changes) => {
changes.forEach(change => {
if(change.attributeName.includes('src')){
self.switchCaptionText(title);
}
})
})
//Telling observer what to observe
observer.observe(img, {attributes: true});
if(e.target.classList.contains("sliderImage")){
const captionHTML = `
<div id="captionArea">
<div class="caption">
${title.textContent}
</div>
</div>`;
imgContainer.insertAdjacentHTML("afterbegin", captionHTML);
}
// Override some default styling on the lightbox
img.style.maxHeight = "70vh"; // set height
img.style.top = "-15vh"; // move up
},
switchCaptionText(text){
const caption = document.querySelector(".caption");
caption.textContent = text.textContent;
}
}
}
</script>
<style lang="scss">
//Hides v-img title element
.title-v-img{
display: none;
}
</style>