1e41f4b71Sopenharmony_ci# Marquee
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **Marquee** component is used to display a scrolling piece of text. The text is scrolled only when its width exceeds the width of the **Marquee** component.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci>  **NOTE**
7e41f4b71Sopenharmony_ci>
8e41f4b71Sopenharmony_ci>  This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
9e41f4b71Sopenharmony_ci>
10e41f4b71Sopenharmony_ci>  To ensure that scrolling frame rates are not affected, it is recommended that the number of **Marquee** components in a scroll container does not exceed four, or alternatively, use the [Text](ts-basic-components-text.md) component's [TextOverflow.MARQUEE](ts-appendix-enums.md#textoverflow) as a substitute.
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci## Child Components
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ciNot supported
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## APIs
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciMarquee(value: { start: boolean, step?: number, loop?: number, fromStart?: boolean, src: string })
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**Parameters**
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description|
30e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
31e41f4b71Sopenharmony_ci| value | { start: boolean, step?: number, loop?: number, fromStart?: boolean, src: string } | Yes| Parameters of the marquee.<br>**start**: whether to start scrolling.<br>**NOTE**<br>This parameter cannot be used to restart scrolling that has been completed.<br>- **step**: scrolling step. If the step is greater than the text width, the default value is taken.<br>Default value: **6**, in vp<br>- **loop**: number of times the marquee will scroll. If the value is less than or equal to **0**, the marquee will scroll continuously.<br>Default value: **-1**<br>**NOTE**<br>Regardless of the value, the marquee scrolls only once on an ArkTS widget.<br>- **fromStart**: whether the text scrolls from the start.<br>Default value: **true**<br>- **src**: text to scroll.|
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci## Attributes
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ciIn addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci### fontColor
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_cifontColor(value: ResourceColor)
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ciSets the font color.
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci**Parameters**
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci| Name| Type                                      | Mandatory| Description      |
52e41f4b71Sopenharmony_ci| ------ | ------------------------------------------ | ---- | ---------- |
53e41f4b71Sopenharmony_ci| value  | [ResourceColor](ts-types.md#resourcecolor) | Yes  | Font color.|
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci### fontSize
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_cifontSize(value: number | string | Resource)
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ciSets the text size.
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci**Parameters**
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci| Name| Type                                                        | Mandatory| Description                                                        |
70e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
71e41f4b71Sopenharmony_ci| value  | [Resource](ts-types.md#resource) \| number \| string | Yes  | Font size. If **fontSize** is of the number type, the unit fp is used. The default font size is 16 fp. This parameter cannot be set in percentage.|
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci### fontWeight
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_cifontWeight(value: number | FontWeight | string)
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ciSets the font weight. If the value is too large, the text may be clipped depending on the font.
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci**Parameters**
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci| Name| Type                                                        | Mandatory| Description                                                        |
88e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
89e41f4b71Sopenharmony_ci| value  | [FontWeight](ts-appendix-enums.md#fontweight) \| number \| string | Yes  | Font weight. For the number type, the value range is [100, 900], at an interval of 100. The default value is **400**. A larger value indicates a heavier font weight. For the string type, only strings that represent a number, for example, **"400"**, and the following enumerated values of **FontWeight** are supported: **"bold"**, **"bolder"**, **"lighter"**, **"regular"**, and **"medium"**.<br>Default value: **FontWeight.Normal**|
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci### fontFamily
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_cifontFamily(value: string | Resource)
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ciSets the font family.
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci**Parameters**
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci| Name| Type                                                | Mandatory| Description                                                        |
106e41f4b71Sopenharmony_ci| ------ | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
107e41f4b71Sopenharmony_ci| value  | [Resource](ts-types.md#resource) \| string | Yes  | Font family. Default font: **'HarmonyOS Sans'**<br>The 'HarmonyOS Sans' font and [registered custom fonts](../js-apis-font.md) are supported for applications.<br>Only the 'HarmonyOS Sans' font is supported for widgets.|
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci### allowScale
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ciallowScale(value: boolean)
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ciSets whether to allow text to scale.
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci**Parameters**
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description                                |
124e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------ |
125e41f4b71Sopenharmony_ci| value  | boolean | Yes  | Whether to allow text to scale.<br>Default value: **false**<br>**NOTE**<br>This parameter is effective only when **fontSize** is in fp units.|
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci### marqueeUpdateStrategy<sup>12+</sup>
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_cimarqueeUpdateStrategy(value: MarqueeUpdateStrategy)
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ciSets the scrolling strategy for the marquee after its attributes are updated. (This attribute takes effect when the marquee is in the playing state and the text content width exceeds the width of the marquee component.)
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci**Parameters**
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description                                |
140e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------ |
141e41f4b71Sopenharmony_ci| value |[MarqueeUpdateStrategy](ts-appendix-enums.md#marqueeupdatestrategy12)| Yes| Scrolling strategy of the marquee after its attributes are updated.<br>Default value: **MarqueeUpdateStrategy.DEFAULT**|
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci## Events
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ci### onStart
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_cionStart(event: () =&gt; void)
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ciCalled when the marquee text changes or starts scrolling.
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci### onBounce
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_cionBounce(event: () =&gt; void)
160e41f4b71Sopenharmony_ci
161e41f4b71Sopenharmony_ciTriggered when the marquee has reached the end. This event will be triggered for multiple times if the **loop** attribute is not set to **1**.
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
166e41f4b71Sopenharmony_ci
167e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
168e41f4b71Sopenharmony_ci
169e41f4b71Sopenharmony_ci### onFinish
170e41f4b71Sopenharmony_ci
171e41f4b71Sopenharmony_cionFinish(event: () =&gt; void)
172e41f4b71Sopenharmony_ci
173e41f4b71Sopenharmony_ciTriggered when the marquee has finished the number of scrolling times set by the **loop** attribute.
174e41f4b71Sopenharmony_ci
175e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
176e41f4b71Sopenharmony_ci
177e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
178e41f4b71Sopenharmony_ci
179e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ci## Example
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci```ts
185e41f4b71Sopenharmony_ci// xxx.ets
186e41f4b71Sopenharmony_ci@Entry
187e41f4b71Sopenharmony_ci@Component
188e41f4b71Sopenharmony_cistruct MarqueeExample {
189e41f4b71Sopenharmony_ci  @State start: boolean = false
190e41f4b71Sopenharmony_ci  @State src: string = ''
191e41f4b71Sopenharmony_ci  @State marqueeText: string = 'Running Marquee'
192e41f4b71Sopenharmony_ci  private fromStart: boolean = true
193e41f4b71Sopenharmony_ci  private step: number = 10
194e41f4b71Sopenharmony_ci  private loop: number = Number.POSITIVE_INFINITY
195e41f4b71Sopenharmony_ci  controller: TextClockController = new TextClockController()
196e41f4b71Sopenharmony_ci  convert2time(value: number): string{
197e41f4b71Sopenharmony_ci    let date = new Date(Number(value+'000'));
198e41f4b71Sopenharmony_ci    let hours = date.getHours().toString().padStart(2, '0');
199e41f4b71Sopenharmony_ci    let minutes = date.getMinutes().toString().padStart(2, '0');
200e41f4b71Sopenharmony_ci    let seconds = date.getSeconds().toString().padStart(2, '0');
201e41f4b71Sopenharmony_ci    return hours+ ":" + minutes + ":" + seconds;
202e41f4b71Sopenharmony_ci  }
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci  build() {
205e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
206e41f4b71Sopenharmony_ci      Marquee({
207e41f4b71Sopenharmony_ci        start: this.start,
208e41f4b71Sopenharmony_ci        step: this.step,
209e41f4b71Sopenharmony_ci        loop: this.loop,
210e41f4b71Sopenharmony_ci        fromStart: this.fromStart,
211e41f4b71Sopenharmony_ci        src: this.marqueeText + this.src
212e41f4b71Sopenharmony_ci      })
213e41f4b71Sopenharmony_ci        .marqueeUpdateStrategy(MarqueeUpdateStrategy.PRESERVE_POSITION)
214e41f4b71Sopenharmony_ci        .width(300)
215e41f4b71Sopenharmony_ci        .height(80)
216e41f4b71Sopenharmony_ci        .fontColor('#FFFFFF')
217e41f4b71Sopenharmony_ci        .fontSize(48)
218e41f4b71Sopenharmony_ci        .fontWeight(700)
219e41f4b71Sopenharmony_ci        .backgroundColor('#182431')
220e41f4b71Sopenharmony_ci        .margin({ bottom: 40 })
221e41f4b71Sopenharmony_ci        .onStart(() => {
222e41f4b71Sopenharmony_ci          console.info('Marquee animation complete onStart')
223e41f4b71Sopenharmony_ci        })
224e41f4b71Sopenharmony_ci        .onBounce(() => {
225e41f4b71Sopenharmony_ci          console.info('Marquee animation complete onBounce')
226e41f4b71Sopenharmony_ci        })
227e41f4b71Sopenharmony_ci        .onFinish(() => {
228e41f4b71Sopenharmony_ci          console.info('Marquee animation complete onFinish')
229e41f4b71Sopenharmony_ci        })
230e41f4b71Sopenharmony_ci      Button('Start')
231e41f4b71Sopenharmony_ci        .onClick(() => {
232e41f4b71Sopenharmony_ci          this.start = true
233e41f4b71Sopenharmony_ci          // Start the text clock.
234e41f4b71Sopenharmony_ci          this.controller.start()
235e41f4b71Sopenharmony_ci        })
236e41f4b71Sopenharmony_ci        .width(120)
237e41f4b71Sopenharmony_ci        .height(40)
238e41f4b71Sopenharmony_ci        .fontSize(16)
239e41f4b71Sopenharmony_ci        .fontWeight(500)
240e41f4b71Sopenharmony_ci        .backgroundColor('#007DFF')
241e41f4b71Sopenharmony_ci      TextClock({ timeZoneOffset: -8, controller: this.controller })
242e41f4b71Sopenharmony_ci        .format('hms')
243e41f4b71Sopenharmony_ci        .onDateChange((value: number) => {
244e41f4b71Sopenharmony_ci          this.src = this.convert2time(value);
245e41f4b71Sopenharmony_ci        })
246e41f4b71Sopenharmony_ci        .margin(20)
247e41f4b71Sopenharmony_ci        .fontSize(30)
248e41f4b71Sopenharmony_ci    }
249e41f4b71Sopenharmony_ci    .width('100%')
250e41f4b71Sopenharmony_ci    .height('100%')
251e41f4b71Sopenharmony_ci  }
252e41f4b71Sopenharmony_ci}
253e41f4b71Sopenharmony_ci```
254e41f4b71Sopenharmony_ci
255e41f4b71Sopenharmony_ci![marquee](figures/marquee.gif)
256