Skip to content

Commit

Permalink
add support for transitional background images
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Coulson committed Apr 2, 2024
1 parent 8e27256 commit ec4d3fe
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"slides": [
{
"title": "Overview",
"backgroundImage": "00000000-0000-0000-0000-000000000000/assets/en/GettyImages-516166467__1554821531978__w1920.jpg",
"panel": [
{
"title": "Overview",
Expand All @@ -26,6 +27,7 @@
},
{
"title": "Default RAMP4 Sample",
"backgroundImage": "00000000-0000-0000-0000-000000000000/assets/en/GettyImages-187242601__1554821467033__w1920.jpg",
"panel": [
{
"config": "00000000-0000-0000-0000-000000000000/ramp-config/test-ramp4.json",
Expand All @@ -41,6 +43,7 @@
},
{
"title": "Dynamic Panel Test",
"backgroundImage": "00000000-0000-0000-0000-000000000000/assets/en/GettyImages-516166467__1554821531978__w1920.jpg",
"panel": [
{
"title": "This Slide Is Dynamic!",
Expand Down Expand Up @@ -127,6 +130,8 @@
},
{
"title": "Video Panel",
"backgroundImage": "00000000-0000-0000-0000-000000000000/assets/en/GettyImages-516166467__1554821531978__w1920.jpg",

"panel": [
{
"title": "Video Test for YoutTube content",
Expand Down Expand Up @@ -174,6 +179,8 @@
},
{
"title": "In-situ extraction",
"backgroundImage": "00000000-0000-0000-0000-000000000000/assets/en/GettyImages-187242601__1554821467033__w1920.jpg",

"panel": [
{
"title": "In-situ extraction",
Expand Down Expand Up @@ -203,6 +210,7 @@
},
{
"title": "NPRI substances reported for oil sands mining facilities",
"backgroundImage": "00000000-0000-0000-0000-000000000000/assets/en/GettyImages-516166467__1554821531978__w1920.jpg",
"panel": [
{
"title": "NPRI substances reported for oil sands mining facilities",
Expand Down
14 changes: 13 additions & 1 deletion src/components/panels/dynamic-panel.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<template>
<div ref="el" :id="key" class="story-slide w-full h-full flex sm:flex-row flex-col">
<VueScrollama class="flex-1 order-2 sm:order-1 prose max-w-none my-5">
<VueScrollama
class="flex-1 order-2 sm:order-1 prose max-w-none my-5 mx-1 py-5"
:class="{ 'has-background': background }"
>
<component
:is="config.titleTag || 'h2'"
class="px-10 mb-0 chapter-title top-20"
Expand Down Expand Up @@ -36,6 +39,7 @@
:slideIdx="slideIdx"
:dynamicIdx="activeIdx"
:ratio="false"
:background="background"
ref="content"
>
</panel>
Expand All @@ -60,6 +64,9 @@ const props = defineProps({
},
slideIdx: {
type: Number
},
background: {
type: Boolean
}
});
Expand Down Expand Up @@ -174,6 +181,11 @@ const clickBack = (): void => {
.return-button img {
margin: 0px;
}
.has-background {
background-color: rgba(255, 255, 255, 0.6);
border-radius: 20px;
color: black;
}
@media screen and (max-width: 640px) {
.return-button-container {
Expand Down
13 changes: 11 additions & 2 deletions src/components/panels/image-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
:class="config.class"
:alt="config.altText || ''"
:style="{ width: `${config.width}px`, height: `${config.height}px` }"
class="graphic-image px-10 mx-auto my-6 flex object-contain sm:max-w-screen sm:max-h-screen"
class="graphic-image px-10 mx-auto flex object-contain sm:max-w-screen sm:max-h-screen"
/>
</fullscreen>

<div
v-if="config.caption"
class="text-center text-sm max-w-full graphic-caption"
v-html="md.render(config.caption)"
:class="{ 'has-background': background }"
></div>
</div>
</template>
Expand All @@ -38,6 +39,9 @@ const props = defineProps({
slideIdx: {
type: Number,
default: 0
},
background: {
type: Boolean
}
});
Expand Down Expand Up @@ -76,7 +80,12 @@ onMounted((): void => {
});
</script>

<style lang="scss">
<style lang="scss" scoped>
.has-background {
background-color: rgba(255, 255, 255, 1);
border-radius: 0px 0px 20px 20px;
color: black;
}
@media screen and (max-width: 640px) {
.graphic {
max-width: 100vw;
Expand Down
16 changes: 15 additions & 1 deletion src/components/panels/map-panel.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<template>
<div ref="el" class="flex flex-col h-full align-middle w-full">
<div class="px-10 mb-0 chapter-title top-20 map-title text-center" v-if="config.title">
<div
class="px-10 mb-0 chapter-title top-20 map-title text-center"
:class="{ 'has-background': background }"
v-if="config.title"
>
{{ config.title }}
</div>
<div :id="`ramp-map-${slideIdx}`" class="w-full bg-gray-200 h-story rv-map"></div>
Expand Down Expand Up @@ -29,6 +33,9 @@ const props = defineProps({
},
configFileStructure: {
type: Object as PropType<ConfigFileStructure>
},
background: {
type: Boolean
}
});
Expand Down Expand Up @@ -119,6 +126,13 @@ const init = async () => {
width: 100%;
}
.has-background {
background-color: rgba(255, 255, 255, 0.6);
margin-bottom: 0em !important;
padding-bottom: 1em;
color: black;
}
.map-title {
color: #111827;
font-weight: 700;
Expand Down
4 changes: 4 additions & 0 deletions src/components/panels/panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
:slideIdx="slideIdx"
:lang="lang"
:style="config.customStyles"
:background="background"
></component>
</div>
</template>
Expand Down Expand Up @@ -51,6 +52,9 @@ const props = defineProps({
},
lang: {
type: String
},
background: {
type: Boolean
}
});
Expand Down
18 changes: 17 additions & 1 deletion src/components/panels/slideshow-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@
</template>
</carousel>

<div v-if="config.caption" class="text-center mt-5 text-sm" v-html="md.render(config.caption)"></div>
<div
v-if="config.caption"
class="text-center mt-5 text-sm"
:class="{ 'has-background': background }"
v-html="md.render(config.caption)"
></div>
</div>
</div>
</div>
Expand Down Expand Up @@ -73,6 +78,9 @@ const props = defineProps({
slideIdx: {
type: Number,
required: true
},
background: {
type: Boolean
}
});
Expand All @@ -91,6 +99,14 @@ window.addEventListener('resize', () => {
</script>

<style lang="scss" scoped>
.has-background {
background-color: rgba(255, 255, 255, 1);
border-radius: 0px 0px 20px 20px;
color: black;
margin-top: 0px !important;
padding-top: 5px;
}
.carousel {
height: auto;
text-align: left;
Expand Down
11 changes: 10 additions & 1 deletion src/components/panels/text-panel.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<VueScrollama class="prose max-w-none my-5">
<VueScrollama class="prose max-w-none my-5 mx-1 py-5" :class="{ 'has-background': background }">
<component :is="config.titleTag || 'h2'" class="px-10 mb-0 chapter-title top-20">
{{ config.title }}
</component>
Expand All @@ -20,6 +20,9 @@ const props = defineProps({
config: {
type: Object as PropType<TextPanel>,
required: true
},
background: {
type: Boolean
}
});
Expand All @@ -39,6 +42,12 @@ onMounted((): void => {
</script>

<style scoped lang="scss">
.has-background {
background-color: rgba(255, 255, 255, 0.6);
border-radius: 20px;
color: black;
}
@media screen and (max-width: 640px) {
.chapter-title {
max-width: 100vw;
Expand Down
85 changes: 85 additions & 0 deletions src/components/story/background-image.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<template>
<div class="sticky z-10 grid-background" style="top: 60px; height: 100vh">
<!-- Vue3 transition for switching between a slide with no background a slide with a background. -->
<Transition name="fade" mode="out-in">
<div v-if="newImage !== 'none'" class="w-full h-full">
<img v-if="oldImage !== 'none'" class="fade-in w-full h-full" :src="oldImage" />
<img class="fade-in w-full h-full" :class="{ hide: activeImage === 1 }" :src="newImage" />
</div>
<div class="w-full h-full" v-else></div>
</Transition>
</div>
</template>

<script setup>
import { watch, ref } from 'vue';
const emit = defineEmits(['background-changed']);
const props = defineProps({
src: {
type: String,
required: true
}
});
const oldImage = ref('none');
const newImage = ref('none');
const activeImage = ref(0);
watch(
() => props.src,
() => {
// Here's how the fancy crossfade works. We have a primary image element and a secondary image element.
// The primary element is what's displaying the current slide background, and the secondary element is only used
// DURING a transition period.
// When a new slide comes into view with a background applied, we display this background on the secondary component
// whilst gradually transitioning the opacity of the primary element to 0 (triggers when `activeImage` is 1). This gives
// us the effect of the new background smoothly coming in. Once the opacity hits 0, we move the new background image
// to the primary element and set the opacity back to 1.
oldImage.value = props.src;
activeImage.value = 1;
// This is the crossfade case where we're switching between two background images.
if (props.src !== 'none' && newImage.value !== 'none') {
setTimeout(() => {
activeImage.value = 0;
oldImage.value = newImage.value;
newImage.value = props.src;
emit('background-changed', true);
}, 350); // timeout length is set to animation time (0.3s) plus a little bit of buffer.
} else {
// Not a crossfade case. We're either transitioning from nothing into an image or from an image into nothing.
// This case uses Vue3 transitions.
newImage.value = props.src;
activeImage.value = 0;
emit('background-changed', newImage.value !== 'none');
}
},
{ immediate: false }
);
</script>

<style scoped>
.hide {
opacity: 0 !important;
transition: opacity 0.3s linear;
}
img {
position: absolute;
opacity: 1;
}
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.2s ease-in;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
</style>
Loading

0 comments on commit ec4d3fe

Please sign in to comment.