93 lines
2.1 KiB
Vue
93 lines
2.1 KiB
Vue
<script setup lang="ts">
|
|
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
|
|
const brandName = '慧众易'
|
|
const messages = ['真容易', '算费真容易', '算费不熬夜', '算费不费力', '不熬夜,不费力']
|
|
const messageIndex = ref(0)
|
|
let rotationTimer: ReturnType<typeof setInterval> | null = null
|
|
|
|
const activeMessage = computed(() => {
|
|
if (!messages.length) return ''
|
|
return messages[((messageIndex.value % messages.length) + messages.length) % messages.length]
|
|
})
|
|
|
|
const stopRotation = () => {
|
|
if (rotationTimer == null) return
|
|
clearInterval(rotationTimer)
|
|
rotationTimer = null
|
|
}
|
|
|
|
const startRotation = () => {
|
|
stopRotation()
|
|
if (messages.length <= 1) return
|
|
rotationTimer = setInterval(() => {
|
|
messageIndex.value = (messageIndex.value + 1) % messages.length
|
|
}, 2400)
|
|
}
|
|
|
|
onMounted(() => {
|
|
startRotation()
|
|
})
|
|
|
|
onBeforeUnmount(() => {
|
|
stopRotation()
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<div class="hero-brand-ticker">
|
|
<span class="hero-brand-ticker__brand">{{ brandName }}</span>
|
|
<span class="hero-brand-ticker__divider" />
|
|
<Transition name="hero-brand-message" mode="out-in">
|
|
<span :key="messageIndex" class="hero-brand-ticker__message">{{ activeMessage }}</span>
|
|
</Transition>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.hero-brand-ticker {
|
|
display: inline-flex;
|
|
max-width: 100%;
|
|
align-items: center;
|
|
gap: 12px;
|
|
padding: 8px 16px;
|
|
color: rgba(255, 255, 255, 0.9);
|
|
border: 1px solid rgba(255, 255, 255, 0.15);
|
|
border-radius: 999px;
|
|
backdrop-filter: blur(8px);
|
|
background: rgba(255, 255, 255, 0.1);
|
|
}
|
|
|
|
.hero-brand-ticker__brand {
|
|
flex-shrink: 0;
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
letter-spacing: 0.28em;
|
|
color: #fff;
|
|
}
|
|
|
|
.hero-brand-ticker__divider {
|
|
width: 1px;
|
|
height: 14px;
|
|
flex-shrink: 0;
|
|
background: rgba(255, 255, 255, 0.25);
|
|
}
|
|
|
|
.hero-brand-ticker__message {
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.hero-brand-message-enter-active,
|
|
.hero-brand-message-leave-active {
|
|
transition: opacity 0.22s ease, transform 0.22s ease;
|
|
}
|
|
|
|
.hero-brand-message-enter-from,
|
|
.hero-brand-message-leave-to {
|
|
opacity: 0;
|
|
transform: translateY(6px);
|
|
}
|
|
</style>
|