Skip to content

TextScroll 文字滚动

文字滚动组件,适用于公告、通知等场景,支持无缝滚动和打字机效果。

🎯 在线演示https://vue.youlai.tech/#/demo/text-scroll

基本用法

vue
<template>
  <TextScroll :text="message" />
</template>

<script setup lang="ts">
const message = ref('系统将于今晚22:00进行维护升级,请提前保存工作内容。')
</script>

不同样式类型

vue
<template>
  <div class="demo-container">
    <TextScroll text="默认样式公告" type="default" />
    <TextScroll text="成功样式公告" type="success" />
    <TextScroll text="警告样式公告" type="warning" />
    <TextScroll text="危险样式公告" type="danger" />
    <TextScroll text="信息样式公告" type="info" />
  </div>
</template>

自定义速度和方向

vue
<template>
  <!-- 滚动速度:数值越小越快 -->
  <TextScroll :text="message" :speed="50" />
  
  <!-- 向右滚动 -->
  <TextScroll :text="message" direction="right" />
</template>

打字机效果

vue
<template>
  <TextScroll 
    :text="message" 
    :typewriter="true"
    :typewriter-speed="80"
  />
</template>

<script setup lang="ts">
const message = ref('欢迎使用 vue3-element-admin 后台管理系统')
</script>

可关闭公告

vue
<template>
  <TextScroll 
    :text="message" 
    :show-close="true"
    @close="handleClose"
  />
</template>

<script setup lang="ts">
const message = ref('这是一条可关闭的公告')

function handleClose() {
  console.log('公告已关闭')
}
</script>

表格中使用

在表格头部或顶部显示公告:

vue
<template>
  <div class="table-container">
    <TextScroll 
      text="温馨提示:请谨慎操作删除功能" 
      type="warning"
      :show-close="true"
    />
    <el-table :data="tableData">
      <!-- 表格列 -->
    </el-table>
  </div>
</template>

Props

参数说明类型默认值
text滚动文本内容(必填)string-
speed滚动速度,数值越小越快number70
direction滚动方向'left' | 'right''left'
type样式类型'default' | 'success' | 'warning' | 'danger' | 'info''default'
showClose是否显示关闭按钮booleanfalse
typewriter是否启用打字机效果booleanfalse
typewriterSpeed打字机速度,数值越小越快number100

Events

事件名说明回调参数
close关闭按钮点击时触发-

样式类型效果

type效果
default主要样式(蓝色)
success成功样式(绿色)
warning警告样式(橙色)
danger危险样式(红色)
info信息样式(灰色)

功能特性

  • ✅ 无缝滚动
  • ✅ 鼠标悬停暂停
  • ✅ 可调节速度和方向
  • ✅ 多种预设样式
  • ✅ 打字机效果
  • ✅ 可关闭

使用场景

  • 系统公告
  • 通知消息
  • 新闻滚动
  • 警告提示
  • 营销活动

注意事项

  1. HTML 内容text 支持 HTML,使用时需注意 XSS 风险
  2. 打字机效果:启用打字机效果时,会在打字完成后才开始滚动
  3. 性能优化:内容过长时建议适当调整 speed

相关链接

基于 MIT 许可发布