<scroll-text>

<scroll-text> 是一个横向滚动文字的容器,主要用于单行公告。

子组件

预览效果

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

&lt;scroll-text&gt; - 图1

示例代码

  1. <template>
  2. <div class="app">
  3. <scroll-text
  4. ref="reflectName"
  5. class="scroll_text"
  6. text="scrollText"
  7. speed="2"
  8. fontSize="32"
  9. @itemClick="itemClick"
  10. ></scroll-text>
  11. <scroll-text
  12. ref="reflectName2"
  13. class="scroll_text"
  14. text="scrollText"
  15. speed="10"
  16. fontSize="32"
  17. color="#ff0000"
  18. backgroundColor="#00ffff"
  19. @itemClick="itemClick"
  20. ></scroll-text>
  21. <scroll-text
  22. ref="reflectName3"
  23. class="scroll_text"
  24. text="scrollText"
  25. speed="5"
  26. fontSize="24"
  27. color="#6dff28"
  28. backgroundColor="#c8e7ff"
  29. @itemClick="itemClick"
  30. ></scroll-text>
  31. </div>
  32. </template>
  33. <style scoped>
  34. .app {
  35. width: 750px;
  36. flex: 1;
  37. }
  38. .scroll_text {
  39. width: 750px;
  40. height: 80px;
  41. }
  42. </style>
  43. <script>
  44. const eeui = app.requireModule('eeui');
  45. export default {
  46. data() {
  47. return {
  48. scrollText: "这是一段滚动的文字,可以自定义调整速度的滚动文字~~~~~感谢你对eeui的支持!",
  49. }
  50. },
  51. methods: {
  52. itemClick(params) {
  53. let starting = params.isStarting ? "运行中": "停止了";
  54. eeui.toast("我被点击了,当前状态:" + starting);
  55. },
  56. }
  57. };
  58. </script>

配置参数

属性名 类型 描述 默认值
content String 滚动的文字 -
text String content -
speed Float 滚动的速度 2
fontSize Number 字体大小 24
color String 滚动的文字颜色 #000000
backgroundColor String 滚动的文字背景颜色 #00ffffff

例如:

  1. <scroll-text
  2. ref="reflectName"
  3. text="滚动的文字"
  4. speed="5"
  5. fontSize="24"
  6. color="#6dff28"
  7. backgroundColor="#c8e7ff"
  8. ></scroll-text>

事件回调 callback

  1. /**
  2. * 组件加载完成
  3. */
  4. @ready = function() { ... }
  5. /**
  6. * 项目点击事件
  7. * 返回参数:data = {isStarting: false}
  8. */
  9. @itemClick = function(data) { ... }

调用方法 methods

  1. /**
  2. * 设置滚动的文字
  3. * 参数一:滚动文字
  4. */
  5. this.$refs.reflectName.setText('滚动文字');
  6. /**
  7. * 添加滚动的文字
  8. * 参数一:添加的滚动文字
  9. */
  10. this.$refs.reflectName.addText('滚动文字');
  11. /**
  12. * 设置为滚动状态
  13. */
  14. this.$refs.reflectName.startScroll();
  15. /**
  16. * 设置为停止滚动状态
  17. */
  18. this.$refs.reflectName.stopScroll();
  19. /**
  20. * 获取是否在滚动状态
  21. * 返回参数:true|false
  22. */
  23. this.$refs.reflectName.isStarting();
  24. /**
  25. * 设置文字滚动速度
  26. * 参数一:滚动速度
  27. */
  28. this.$refs.reflectName.setSpeed(3);
  29. /**
  30. * 设置滚动字体大小
  31. * 参数一:文字大小
  32. */
  33. this.$refs.reflectName.setTextSize(16);
  34. /**
  35. * 设置滚动字体颜色
  36. * 参数一:颜色代码
  37. */
  38. this.$refs.reflectName.setTextColor('#ff0000');
  39. /**
  40. * 设置滚动字体背景颜色
  41. * 参数一:颜色代码
  42. */
  43. this.$refs.reflectName.setBackgroundColor('#0000ff');