enhance(client): better marquee component

This commit is contained in:
syuilo
2022-07-02 21:28:04 +09:00
parent 949dbb3918
commit ef83670716
5 changed files with 100 additions and 17 deletions

View File

@ -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>

View File

@ -47,8 +47,8 @@
<script lang="ts" setup>
import { } from 'vue';
import { toUnicode } from 'punycode/';
import MarqueeText from 'vue-marquee-text-component';
import XTimeline from './welcome.timeline.vue';
import MarqueeText from '@/components/marquee.vue';
import XSigninDialog from '@/components/signin-dialog.vue';
import XSignupDialog from '@/components/signup-dialog.vue';
import MkButton from '@/components/ui/button.vue';

View File

@ -18,8 +18,8 @@
<script lang="ts" setup>
import { onMounted, onUnmounted, ref, watch } from 'vue';
import MarqueeText from 'vue-marquee-text-component';
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
import MarqueeText from '@/components/marquee.vue';
import { GetFormResultType } from '@/scripts/form';
import * as os from '@/os';
import MkContainer from '@/components/ui/container.vue';