Sharkey/packages/frontend/src/pages/welcome.timeline.vue

103 lines
2.6 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->
2020-12-30 16:22:20 +01:00
<template>
<div :class="$style.root" class="_gaps">
<div
ref="notesMainContainerEl"
class="_gaps"
:class="[$style.scrollBoxMain, { [$style.scrollIntro]: (scrollState === 'intro'), [$style.scrollLoop]: (scrollState === 'loop') }]"
@animationend="changeScrollState"
>
<XNote v-for="note in notes" :key="`${note.id}_1`" :class="$style.note" :note="note"/>
</div>
<div v-if="isScrolling" class="_gaps" :class="[$style.scrollBoxSub, { [$style.scrollIntro]: (scrollState === 'intro'), [$style.scrollLoop]: (scrollState === 'loop') }]">
<XNote v-for="note in notes" :key="`${note.id}_2`" :class="$style.note" :note="note"/>
2020-12-30 16:22:20 +01:00
</div>
</div>
</template>
<script lang="ts" setup>
import * as Misskey from 'misskey-js';
import { onUpdated, ref, shallowRef } from 'vue';
import XNote from '@/pages/welcome.timeline.note.vue';
import { misskeyApiGet } from '@/scripts/misskey-api.js';
2023-09-19 09:37:43 +02:00
import { getScrollContainer } from '@/scripts/scroll.js';
2020-12-30 16:22:20 +01:00
const notes = ref<Misskey.entities.Note[]>([]);
const isScrolling = ref(false);
const scrollState = ref<null | 'intro' | 'loop'>(null);
const notesMainContainerEl = shallowRef<HTMLElement>();
2020-12-30 16:22:20 +01:00
misskeyApiGet('notes/featured').then(_notes => {
notes.value = _notes;
});
function changeScrollState() {
if (scrollState.value !== 'loop') {
scrollState.value = 'loop';
}
}
onUpdated(() => {
if (!notesMainContainerEl.value) return;
const container = getScrollContainer(notesMainContainerEl.value);
const containerHeight = container ? container.clientHeight : window.innerHeight;
if (notesMainContainerEl.value.offsetHeight > containerHeight) {
if (scrollState.value === null) {
scrollState.value = 'intro';
}
isScrolling.value = true;
}
2020-12-30 16:22:20 +01:00
});
</script>
<style lang="scss" module>
@keyframes scrollIntro {
0% {
transform: translate3d(0, 0, 0);
}
100% {
transform: translate3d(0, calc(calc(-100% - 128px) - var(--margin)), 0);
}
}
@keyframes scrollConstant {
0% {
transform: translate3d(0, -128px, 0);
}
100% {
transform: translate3d(0, calc(calc(-100% - 128px) - var(--margin)), 0);
}
}
.root {
2020-12-30 16:22:20 +01:00
text-align: right;
}
2020-12-30 16:22:20 +01:00
.scrollBoxMain {
&.scrollIntro {
animation: scrollIntro 30s linear forwards;
}
&.scrollLoop {
animation: scrollConstant 30s linear infinite;
}
}
.scrollBoxSub {
&.scrollIntro {
animation: scrollIntro 30s linear forwards;
}
&.scrollLoop {
animation: scrollConstant 30s linear infinite;
}
}
2020-12-30 16:22:20 +01:00
.root:has(.note:hover) .scrollBoxMain,
.root:has(.note:hover) .scrollBoxSub {
animation-play-state: paused;
2020-12-30 16:22:20 +01:00
}
</style>