ts-basic-components-marquee.md 3.0 KB
Newer Older
E
add doc  
ester.zhou 已提交
1 2
# Marquee

E
ester.zhou 已提交
3 4
The **\<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.

E
add doc  
ester.zhou 已提交
5

E
ester.zhou 已提交
6 7 8
>  **NOTE**
>
>  This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
E
add doc  
ester.zhou 已提交
9 10 11 12


## Child Components

E
ester.zhou 已提交
13
Not supported
E
add doc  
ester.zhou 已提交
14 15 16 17 18 19


## APIs

Marquee(value: { start: boolean, step?: number, loop?: number, fromStart?: boolean, src: string })

E
ester.zhou 已提交
20 21 22 23 24 25 26 27 28 29 30
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| start | boolean | Yes| Whether to start scrolling.|
| step | number | No| Scrolling step.<br>Default value: **6**, in vp|
| loop | number | No| 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**|
| fromStart | boolean | No| Whether the text scrolls from the start.<br>Default value: **true**|
| src | string | Yes| Text to scroll.|

## Attributes
E
add doc  
ester.zhou 已提交
31

E
ester.zhou 已提交
32 33 34
| Name      | Type| Description                                |
| ---------- | -------- | ------------------------------------ |
| allowScale | boolean  | Whether to allow text to scale.<br>Default value: **false**|
E
add doc  
ester.zhou 已提交
35 36 37

## Events

E
ester.zhou 已提交
38
| Name| Description|
E
add doc  
ester.zhou 已提交
39
| -------- | -------- |
E
ester.zhou 已提交
40 41 42
| onStart(event: () =&gt; void) | Triggered when the marquee starts scrolling.|
| onBounce(event: () =&gt; void) | Triggered when the marquee has reached the end. This event will be triggered for multiple times if the **loop** attribute is not set to **1**.|
| onFinish(event: () =&gt; void) | Triggered when the marquee has finished the number of scrolling times set by the **loop** attribute.|
E
add doc  
ester.zhou 已提交
43 44 45 46 47


## Example


E
ester.zhou 已提交
48 49
```ts
// xxx.ets
E
add doc  
ester.zhou 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
@Entry
@Component
struct MarqueeExample {
  @State start: boolean = false
  @State fromStart: boolean = true
  @State step: number = 50
  @State loop: number = 3
  @State src: string = "Running Marquee starts rolling"

  build() {
    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
      Marquee({
        start: this.start,
        step: this.step,
        loop: this.loop,
        fromStart: this.fromStart,
        src: this.src
      })
E
ester.zhou 已提交
68
        .width(400)
E
add doc  
ester.zhou 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
        .fontColor(Color.White)
        .fontSize(50)
        .allowScale(false)
        .fontWeight(FontWeight.Bold)
        .backgroundColor(Color.Black)
        .margin({bottom:40})
        .onStart(() => {
          console.log('Marquee animation complete onStart')
        })
        .onBounce(() => {
          console.log('Marquee animation complete onBounce')
        })
        .onFinish(() => {
          console.log('Marquee animation complete onFinish')
        })
        Button('start')
          .onClick(() => {
            this.start = true
E
ester.zhou 已提交
87
          })
E
add doc  
ester.zhou 已提交
88 89 90 91 92 93 94 95 96 97 98
          .width(200)
          .height(60)
          .margin({bottom:20})
    }
    .width('100%')
    .height('100%')
  }
}
```

![en-us_image_0000001193499234](figures/en-us_image_0000001193499234.gif)