2023-07-27 05:31:52 +00:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2022-07-02 12:28:04 +00:00
|
|
|
<script lang="ts">
|
2022-07-02 13:07:04 +00:00
|
|
|
import { h, onMounted, onUnmounted, ref, watch } from 'vue';
|
2022-07-02 12:28:04 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'MarqueeText',
|
|
|
|
props: {
|
|
|
|
duration: {
|
|
|
|
type: Number,
|
|
|
|
default: 15,
|
|
|
|
},
|
|
|
|
repeat: {
|
|
|
|
type: Number,
|
|
|
|
default: 2,
|
|
|
|
},
|
|
|
|
paused: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
reverse: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
setup(props) {
|
2023-12-26 05:19:35 +00:00
|
|
|
const contentEl = ref<HTMLElement>();
|
2022-07-02 12:28:04 +00:00
|
|
|
|
|
|
|
function calc() {
|
2024-01-30 10:53:53 +00:00
|
|
|
if (contentEl.value == null) return;
|
2022-07-02 12:28:04 +00:00
|
|
|
const eachLength = contentEl.value.offsetWidth / props.repeat;
|
|
|
|
const factor = 3000;
|
|
|
|
const duration = props.duration / ((1 / eachLength) * factor);
|
|
|
|
|
|
|
|
contentEl.value.style.animationDuration = `${duration}s`;
|
|
|
|
}
|
|
|
|
|
2022-07-02 13:07:04 +00:00
|
|
|
watch(() => props.duration, calc);
|
|
|
|
|
2022-07-02 12:28:04 +00:00
|
|
|
onMounted(() => {
|
|
|
|
calc();
|
|
|
|
});
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
contentEl,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
render({
|
|
|
|
$slots, $style, $props: {
|
|
|
|
duration, repeat, paused, reverse,
|
|
|
|
},
|
|
|
|
}) {
|
|
|
|
return h('div', { class: [$style.wrap] }, [
|
|
|
|
h('span', {
|
|
|
|
ref: 'contentEl',
|
|
|
|
class: [
|
|
|
|
paused
|
|
|
|
? $style.paused
|
|
|
|
: undefined,
|
|
|
|
$style.content,
|
|
|
|
],
|
|
|
|
}, Array(repeat).fill(
|
|
|
|
h('span', {
|
|
|
|
class: $style.text,
|
|
|
|
style: {
|
|
|
|
animationDirection: reverse
|
|
|
|
? 'reverse'
|
|
|
|
: undefined,
|
|
|
|
},
|
|
|
|
}, $slots.default()),
|
|
|
|
)),
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.wrap {
|
2022-07-13 12:41:06 +00:00
|
|
|
overflow: clip;
|
2022-07-05 07:16:13 +00:00
|
|
|
animation-play-state: running;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
animation-play-state: paused;
|
|
|
|
}
|
2022-07-02 12:28:04 +00:00
|
|
|
}
|
|
|
|
.content {
|
|
|
|
display: inline-block;
|
|
|
|
white-space: nowrap;
|
2022-07-05 07:16:13 +00:00
|
|
|
animation-play-state: inherit;
|
2022-07-02 12:28:04 +00:00
|
|
|
}
|
|
|
|
.text {
|
|
|
|
display: inline-block;
|
|
|
|
animation-name: marquee;
|
|
|
|
animation-timing-function: linear;
|
|
|
|
animation-iteration-count: infinite;
|
|
|
|
animation-duration: inherit;
|
2022-07-05 07:16:13 +00:00
|
|
|
animation-play-state: inherit;
|
2022-07-02 12:28:04 +00:00
|
|
|
}
|
|
|
|
.paused .text {
|
|
|
|
animation-play-state: paused;
|
|
|
|
}
|
|
|
|
@keyframes marquee {
|
|
|
|
0% { transform:translateX(0); }
|
|
|
|
100% { transform:translateX(-100%); }
|
|
|
|
}
|
|
|
|
</style>
|