文档管理中心
您当前正在浏览HarmonyOS最新文档,覆盖已发布的所有API版本,可在API参考中筛选您使用的API版本。详细的版本配套关系请参考版本说明

marquee

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
说明

从API version 4开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。

从API version 6开始,仅当文本内容宽度超过跑马灯组件宽度时滚动。

跑马灯组件,用于展示一段单行滚动的文字。

权限列表

子组件

不支持。

属性

除支持通用属性外,还支持如下属性:

展开
名称 类型 默认值 必填 描述
scrollamount number 6 跑马灯每次滚动时移动的步长。
loop number -1 跑马灯滚动的次数。如果未指定,则默认值为-1,当该值小于等于零时表示跑马灯将连续滚动。
direction string left 设置跑马灯的文字滚动方向,可选值为left和right。

样式

除支持通用样式外,还支持如下样式:

展开
名称 类型 默认值 必填 描述
color <color> #e5000000 设置跑马灯中文字的文本颜色。
font-size <length> 37.5px 设置跑马灯中文字的文本尺寸。
allow-scale boolean true

设置跑马灯中文字的文本尺寸是否跟随系统设置字体缩放尺寸进行放大缩小。true表示跟随系统放大缩小,false表示不跟随系统放大缩小。

如果在config描述文件中针对ability配置了fontSize的config-changes标签,则应用不会重启而直接生效。

font-weight number | string normal 设置跑马灯中文字的字体的粗细,见text组件font-weight的样式属性
font-family string sans-serif 设置跑马灯中文字的字体列表,用逗号分隔,每个字体用字体名或者字体族名设置。列表中第一个系统中存在的或者通过自定义字体指定的字体,会被选中作为文本的字体。

事件

除支持通用事件外,还支持如下事件:

展开
名称 参数 描述
bounce - 当文本滚动到末尾时触发该事件。
finish - 当完成滚动次数时触发该事件。需要在 loop 属性值大于 0 时触发。
start - 当文本滚动开始时触发该事件。

方法

除支持通用方法外,还支持如下方法:

展开
名称 参数 描述
start - 开始滚动。
stop - 停止滚动。

示例

收起
自动换行
深色代码主题
复制
  1. <!-- xxx.hml -->
  2. <div class="tutorial-page">
  3. <div class="myMarquee">
  4. <marquee style="color: {{color1}}" loop="{{loopVal}}" scrollamount="{{scroll}}" direction="{{isLeft}}" class="marqueeText"
  5. id="testMarquee" onfinish="setFinish">
  6. Life is a journey, not the destination.
  7. </marquee>
  8. </div>
  9. <div style="width: 600px;height: 150px;flex-direction: row;justify-content: space-around;">
  10. <button onclick="makeStart" value="start"></button>
  11. <button onclick="makeStop" value="stop"></button>
  12. </div>
  13. </div>
收起
自动换行
深色代码主题
复制
  1. /* xxx.css */
  2. .tutorial-page {
  3. width: 750px;
  4. height: 100%;
  5. flex-direction: column;
  6. align-items: center;
  7. justify-content: center;
  8. }
  9. .marqueeText {
  10. font-size: 40px;
  11. }
  12. .myMarquee {
  13. margin-top: 20px;
  14. width:100%;
  15. height: 100px;
  16. margin-left: 50px;
  17. margin-right: 50px;
  18. border: 1px solid #dc0f27;
  19. border-radius: 15px;
  20. align-items: center;
  21. }
  22. button{
  23. width: 200px;
  24. height: 80px;
  25. margin-top: 100px;
  26. }
收起
自动换行
深色代码主题
复制
  1. // xxx.js
  2. export default {
  3. private: {
  4. loopVal: 1,
  5. scroll: 8,
  6. color1: 'red',
  7. isLeft: 'left',
  8. r: 255,
  9. g: 0,
  10. b: 0
  11. },
  12. onInit(){
  13. },
  14. setFinish(e) {
  15. this.loopVal= this.loopVal + 1,
  16. this.r = Math.floor(Math.random()*255),
  17. this.g = Math.floor(Math.random()*255),
  18. this.b = Math.floor(Math.random()*255),
  19. this.color1 = 'rgba('+ this.r +','+ this.g +','+ this.b +',0.8)',
  20. this.$element('testMarquee').start(),
  21. this.loopVal= this.loopVal - 1
  22. },
  23. makeStart(e) {
  24. this.$element('testMarquee').start()
  25. },
  26. makeStop(e) {
  27. this.$element('testMarquee').stop()
  28. }
  29. }

相关推荐
文档Marquee
文档input
文档search
文档progress
文档label
文档menu
文档textarea
文档button
文档text
文档rating
在 API参考 中进行搜索
请输入您想要搜索的关键词