<marquee>

<marquee> 是一个横向自动滚动文字的容器,主要用于文字多单地方小的地方,比如单行标题。

子组件

预览效果

说明:gif图片压缩,原效果非常流畅。

&lt;marquee&gt; - 图1

示例代码

  1. <template>
  2. <div class="app">
  3. <marquee
  4. ref="reflectName"
  5. class="marquee"
  6. style="width:750px;height:50px;font-size:24px"
  7. :text="scrollText"
  8. ></marquee>
  9. <marquee
  10. ref="reflectName2"
  11. class="marquee"
  12. style="width:375px;height:50px;font-size:24px;color:#ff0000;background-color:#00ffff"
  13. :text="scrollText"
  14. ></marquee>
  15. <marquee
  16. ref="reflectName3"
  17. class="marquee"
  18. style="width:200px;height:50px;font-size:24px;color:#6e0a92;background-color:#c8e7ff"
  19. :text="scrollText"
  20. ></marquee>
  21. </div>
  22. </template>
  23. <style scoped>
  24. .app {
  25. width: 750px;
  26. flex: 1;
  27. }
  28. .marquee {
  29. margin-top: 50px;
  30. height: 60px;
  31. background-color: #00B4FF;
  32. }
  33. </style>
  34. <script>
  35. export default {
  36. data() {
  37. return {
  38. scrollText: "地方不够放时才滚动!",
  39. }
  40. }
  41. };
  42. </script>

配置参数

属性名 类型 描述 默认值
content String 显示的文字 -
text String content -
color String 滚动的文字颜色 #000000
fontSize Number 字体大小 24
textAlign String 对齐方式:left center right left
backgroundColor String 滚动的文字背景颜色 #00ffffff

例如:

  1. <marquee
  2. ref="reflectName"
  3. text="地方不够放时才滚动"
  4. fontSize="24"
  5. color="#6dff28"
  6. backgroundColor="#c8e7ff"></marquee>

事件回调 callback

  1. /**
  2. * 组件加载完成
  3. */
  4. @ready = function() { ... }

调用方法 methods

  1. /**
  2. * 设置显示的文字
  3. * 参数一:滚动文字
  4. */
  5. this.$refs.reflectName.setText('文字');
  6. /**
  7. * 添加显示的文字
  8. * 参数一:添加的显示文字
  9. */
  10. this.$refs.reflectName.addText('文字');
  11. /**
  12. * 设置字体大小
  13. * 参数一:文字大小
  14. */
  15. this.$refs.reflectName.setTextSize(24);
  16. /**
  17. * 设置字体颜色
  18. * 参数一:颜色代码
  19. */
  20. this.$refs.reflectName.setTextColor('#ff0000');
  21. /**
  22. * 设置字体背景颜色
  23. * 参数一:颜色代码
  24. */
  25. this.$refs.reflectName.setBackgroundColor('#0000ff');