diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2022-07-02 21:28:04 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2022-07-02 21:28:04 +0900 |
| commit | ef83670716cc93f84c95e03d2a00377352d27d5b (patch) | |
| tree | e9e7567bef305410af108196dd57352e58a80169 /packages/client/src/components | |
| parent | feat(server): add fetch-rss api to reduce dependency of external apis (diff) | |
| download | misskey-ef83670716cc93f84c95e03d2a00377352d27d5b.tar.gz misskey-ef83670716cc93f84c95e03d2a00377352d27d5b.tar.bz2 misskey-ef83670716cc93f84c95e03d2a00377352d27d5b.zip | |
enhance(client): better marquee component
Diffstat (limited to 'packages/client/src/components')
| -rw-r--r-- | packages/client/src/components/marquee.vue | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/packages/client/src/components/marquee.vue b/packages/client/src/components/marquee.vue new file mode 100644 index 0000000000..2fd76a54f0 --- /dev/null +++ b/packages/client/src/components/marquee.vue @@ -0,0 +1,97 @@ +<script lang="ts"> +import { h, onMounted, onUnmounted, ref } from 'vue'; + +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) { + const contentEl = ref(); + + function calc() { + const eachLength = contentEl.value.offsetWidth / props.repeat; + const factor = 3000; + const duration = props.duration / ((1 / eachLength) * factor); + + contentEl.value.style.animationDuration = `${duration}s`; + } + + 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 { + overflow: clip; +} +.content { + display: inline-block; + white-space: nowrap; +} +.text { + display: inline-block; + animation-name: marquee; + animation-timing-function: linear; + animation-iteration-count: infinite; + animation-duration: inherit; +} +.paused .text { + animation-play-state: paused; +} +@keyframes marquee { + 0% { transform:translateX(0); } + 100% { transform:translateX(-100%); } +} +</style> |