2021-01-09 20:36:20 +01:00
|
|
|
<template>
|
2021-01-09 20:53:56 +01:00
|
|
|
<div class="video-scroll" ref="root">
|
2021-01-10 13:12:41 +01:00
|
|
|
<template v-if="definition.direction === 'left' || definition.direction === 'right'">
|
|
|
|
<img class="visible loaded"
|
|
|
|
:src="definition.files[0]"
|
|
|
|
:style="{
|
|
|
|
top: `${Math.round(definition.top)}px`,
|
|
|
|
left: `${Math.round(definition.left)}px`,
|
|
|
|
width: `${Math.round(definition.width)}px`,
|
|
|
|
}"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<!--suppress RequiredAttributes -->
|
|
|
|
<img v-for="(file, idx) in definition.files.slice(1)"
|
|
|
|
:data-src="file"
|
|
|
|
:style="{
|
|
|
|
top: `${Math.round(definition.top)}px`,
|
|
|
|
left: `${Math.round(definition.left) + (definition.width * (idx + 1) * directionSign)}px`,
|
|
|
|
width: `${Math.round(definition.width)}px`,
|
|
|
|
}"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<img class="visible loaded"
|
|
|
|
:src="definition.files[0]"
|
|
|
|
:style="{
|
|
|
|
top: `${Math.round(definition.top)}px`,
|
|
|
|
left: `${Math.round(definition.left)}px`,
|
|
|
|
height: `${Math.round(definition.height)}px`,
|
|
|
|
}"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<!--suppress RequiredAttributes -->
|
|
|
|
<img v-for="(file, idx) in definition.files.slice(1)"
|
|
|
|
:data-src="file"
|
|
|
|
:style="{
|
|
|
|
top: `${Math.round(definition.top) + (definition.height * (idx + 1) * directionSign)}px`,
|
|
|
|
left: `${Math.round(definition.left)}px`,
|
|
|
|
height: `${Math.round(definition.height)}px`,
|
|
|
|
}"
|
|
|
|
/>
|
|
|
|
</template>
|
2021-01-09 20:36:20 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-01-09 20:53:56 +01:00
|
|
|
import {defineComponent, onMounted, ref} from "vue";
|
2021-01-09 20:36:20 +01:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
name: "VideoScroll",
|
|
|
|
props: {
|
|
|
|
definition: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
2021-01-10 13:12:41 +01:00
|
|
|
computed: {
|
|
|
|
directionSign() {
|
|
|
|
if (this.definition.direction == VideoScrollDirection.RIGHT ||
|
|
|
|
this.definition.direction == VideoScrollDirection.DOWN) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-01-09 20:36:20 +01:00
|
|
|
setup(props) {
|
2021-01-09 20:53:56 +01:00
|
|
|
const root = ref<Element | null>(null);
|
2021-01-09 20:36:20 +01:00
|
|
|
|
2021-01-09 20:53:56 +01:00
|
|
|
onMounted(() => {
|
|
|
|
const observer = new IntersectionObserver((entries, observer) => {
|
|
|
|
entries.forEach((entry) => {
|
2021-01-10 00:00:42 +01:00
|
|
|
const element = entry.target as HTMLImageElement;
|
2021-01-09 21:00:30 +01:00
|
|
|
if (entry.isIntersecting) {
|
2021-01-10 00:00:42 +01:00
|
|
|
element.classList.add("visible");
|
|
|
|
if (!element.src) {
|
|
|
|
element.src = element.dataset.src!;
|
|
|
|
element.onload = () => {
|
|
|
|
element.classList.add("loaded");
|
|
|
|
};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
element.classList.remove("visible");
|
2021-01-09 20:53:56 +01:00
|
|
|
}
|
2021-01-09 21:00:30 +01:00
|
|
|
});
|
2021-01-10 13:04:48 +01:00
|
|
|
});
|
2021-01-09 20:53:56 +01:00
|
|
|
Array.from((root.value as Element).children).forEach((el) => {
|
|
|
|
observer.observe(el);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-01-09 20:36:20 +01:00
|
|
|
return {
|
2021-01-10 13:12:41 +01:00
|
|
|
root
|
2021-01-09 20:36:20 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export enum VideoScrollDirection {
|
2021-01-10 13:12:41 +01:00
|
|
|
RIGHT = "right",
|
|
|
|
LEFT = "left",
|
|
|
|
UP = "up",
|
|
|
|
DOWN = "down"
|
2021-01-09 20:36:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface VideoScrollDef {
|
|
|
|
top: number,
|
|
|
|
left: number,
|
2021-01-10 13:12:41 +01:00
|
|
|
width: number,
|
|
|
|
height: number,
|
2021-01-09 20:36:20 +01:00
|
|
|
direction: VideoScrollDirection,
|
2021-01-10 13:12:41 +01:00
|
|
|
files: string[]
|
2021-01-09 20:36:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
|
|
<style scoped>
|
|
|
|
.video-scroll img {
|
|
|
|
position: absolute;
|
2021-01-09 21:00:30 +01:00
|
|
|
image-rendering: optimizeSpeed;
|
2021-01-09 23:56:14 +01:00
|
|
|
opacity: 0;
|
|
|
|
transition: opacity .5s;
|
2021-01-10 00:00:42 +01:00
|
|
|
visibility: hidden;
|
2021-01-09 23:56:14 +01:00
|
|
|
}
|
|
|
|
|
2021-01-10 00:00:42 +01:00
|
|
|
.loaded {
|
2021-01-09 23:56:14 +01:00
|
|
|
opacity: 1 !important;
|
2021-01-09 20:36:20 +01:00
|
|
|
}
|
2021-01-10 00:00:42 +01:00
|
|
|
|
|
|
|
.visible {
|
|
|
|
visibility: visible !important;
|
|
|
|
}
|
2021-01-09 20:36:20 +01:00
|
|
|
</style>
|