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-11 19:29:35 +01:00
|
|
|
<img class="visible loaded"
|
|
|
|
:src="definition.files[0]"
|
|
|
|
:style="{
|
2021-01-10 13:12:41 +01:00
|
|
|
top: `${Math.round(definition.top)}px`,
|
|
|
|
left: `${Math.round(definition.left)}px`,
|
2021-01-11 22:17:29 +01:00
|
|
|
width: isHorizontal ? `${Math.round(definition.width)}px` : 'auto',
|
|
|
|
height: isHorizontal ? 'auto' : `${Math.round(definition.height)}px`,
|
|
|
|
rotate: `${definition.angle}deg`
|
2021-01-10 13:12:41 +01:00
|
|
|
}"
|
2021-01-11 19:29:35 +01:00
|
|
|
/>
|
2021-01-10 13:12:41 +01:00
|
|
|
|
2021-01-11 19:29:35 +01:00
|
|
|
<!--suppress RequiredAttributes -->
|
2021-01-11 22:17:29 +01:00
|
|
|
<img v-for="file in dynamicFiles"
|
|
|
|
:data-src="file.src"
|
2021-01-11 19:29:35 +01:00
|
|
|
:data-direction="definition.direction"
|
|
|
|
:style="{
|
2021-01-11 22:17:29 +01:00
|
|
|
top: `${Math.round(file.top)}px`,
|
|
|
|
left: `${Math.round(file.left)}px`,
|
2021-01-10 13:12:41 +01:00
|
|
|
width: `${Math.round(definition.width)}px`,
|
2021-01-11 19:21:39 +01:00
|
|
|
height: `${Math.round(definition.height)}px`,
|
2021-01-11 22:17:29 +01:00
|
|
|
rotate: `${definition.angle}deg`
|
2021-01-10 13:12:41 +01:00
|
|
|
}"
|
2021-01-11 19:29:35 +01:00
|
|
|
/>
|
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-11 22:17:29 +01:00
|
|
|
import {rotate} from "@/utils";
|
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: {
|
2021-01-11 22:17:29 +01:00
|
|
|
dynamicFiles(): { [key: string]: string } {
|
|
|
|
return this.definition.files.slice(1).map((src: string, idx: number) => {
|
|
|
|
const cy = this.definition.top +
|
|
|
|
(this.isHorizontal ? 0 : (this.definition.height * (idx + 1) * this.direction));
|
|
|
|
const cx = this.definition.left +
|
|
|
|
(this.isHorizontal ? (this.definition.width * (idx + 1) * this.direction) : 0);
|
|
|
|
const [left, top] = rotate(cx, cy, this.definition.left, this.definition.top, this.definition.angle);
|
|
|
|
return {top, left, src};
|
|
|
|
});
|
|
|
|
},
|
|
|
|
isHorizontal(): boolean {
|
|
|
|
return this.definition.direction === "left" || this.definition.direction === "right";
|
|
|
|
},
|
|
|
|
direction(): number {
|
|
|
|
return (this.definition.direction === "right" || this.definition.direction === "down") ? 1 : -1;
|
2021-01-11 19:29:35 +01:00
|
|
|
}
|
|
|
|
},
|
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-11 23:10:40 +01:00
|
|
|
console.debug(`[VIDEOSCROLL] Initializing ${props.definition.files[0]}...`);
|
|
|
|
console.debug(props.definition);
|
|
|
|
|
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
|
|
|
if (!element.src) {
|
2021-01-11 23:10:40 +01:00
|
|
|
console.debug(`[VIDEOSCROLL] Intersected, loading ${element.dataset.src}`);
|
2021-01-10 00:00:42 +01:00
|
|
|
element.src = element.dataset.src!;
|
2021-01-11 19:21:39 +01:00
|
|
|
if (element.dataset.direction == "left" || element.dataset.direction == "right") {
|
|
|
|
element.style.height = "auto";
|
|
|
|
} else {
|
|
|
|
element.style.width = "auto";
|
|
|
|
}
|
2021-01-10 00:00:42 +01:00
|
|
|
element.onload = () => {
|
|
|
|
element.classList.add("loaded");
|
|
|
|
};
|
|
|
|
}
|
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-11 22:17:29 +01:00
|
|
|
angle: 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
|
|
|
.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
|
|
|
|
2021-01-09 20:36:20 +01:00
|
|
|
</style>
|