| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <template>
- <div class="VciTextBounce">
- <span
- v-for="(t, index) in textArray"
- :key="t + index"
- :class="{'tb-up': indexCurrentBounce === index, 'tb-space': /\s/.test(t)}"
- class="tb"
- >
- {{ t }}
- </span>
- </div>
- </template>
- <script>
- import MixinClearScheduleTasks from "../../mixins/MixinClearScheduledTasks";
- export default {
- name: "VciTextBounce",
- mixins: [MixinClearScheduleTasks],
- props: {
- text: {
- type: String,
- default: "bounce"
- }
- },
- data() {
- return {
- indexCurrentBounce: -1,
- inter: -1
- };
- },
- computed: {
- textArray() {
- return (this.text + "...").split("");
- }
- },
- watch: {
- text: {
- handler() {
- this.startBounce();
- },
- immediate: true
- }
- },
- methods: {
- startBounce() {
- this.stopBounce();
- if(this.textArray.length > 2) {
- this.indexCurrentBounce = -1;
- this.inter = setInterval(() => {
- this.indexCurrentBounce++;
- if(this.indexCurrentBounce >= this.textArray.length) this.indexCurrentBounce = -1;
- }, 220);
- }
- },
- stopBounce() {
- clearInterval(this.inter);
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- @use "@vci/style/src/var" as va;
- .VciTextBounce {
- white-space: nowrap;
- .tb {
- display: inline-block;
- transition: va.$transition;
- letter-spacing: .1em;
- &.tb-up {
- transform: translateY(-20%);
- }
- &.tb-space {
- padding: 0 2px;
- }
- }
- }
- </style>
|