1e41f4b71Sopenharmony_ci# ScrollBar
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **\<ScrollBar>** is used together with scrollable components, such as **\<List>**, **\<Grid>**, and **\<Scroll>**.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>  **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci>  This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Child Components
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ciThis component can contain a single child component.
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## APIs
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciScrollBar(value: ScrollBarOptions)
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci**Parameters**
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description|
22e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
23e41f4b71Sopenharmony_ci| value |  [ScrollBarOptions](#scrollbaroptions)| Yes| Scrollbar settings.|
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci## ScrollBarOptions
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description|
28e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
29e41f4b71Sopenharmony_ci| scroller | [Scroller](ts-container-scroll.md#scroller) | Yes| Scroller, which can be bound to scrollable components.|
30e41f4b71Sopenharmony_ci| direction | [ScrollBarDirection](#scrollbardirection) | No| Scrollbar direction in which scrollable components scroll.<br>Default value: **ScrollBarDirection.Vertical**|
31e41f4b71Sopenharmony_ci| state | [BarState](ts-appendix-enums.md#barstate) | No| Scrollbar state.<br>Default value: **BarState.Auto**|
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci>  **NOTE**
34e41f4b71Sopenharmony_ci>
35e41f4b71Sopenharmony_ci> The **\<ScrollBar>** component defines the behavior style of the scrollable area, and its subnodes define the behavior style of the scrollbar.
36e41f4b71Sopenharmony_ci> 
37e41f4b71Sopenharmony_ci> This component is bound to a scrollable component through **scroller**, and can be used to scroll the scrollable component only when their directions are the same. The **\<ScrollBar>** component can be bound to only one scrollable component, and vice versa.
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci## ScrollBarDirection
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci| Name| Description|
42e41f4b71Sopenharmony_ci| -------- | -------- |
43e41f4b71Sopenharmony_ci| Vertical | Vertical scrollbar.|
44e41f4b71Sopenharmony_ci| Horizontal | Horizontal scrollbar.|
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci## Example
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci```ts
50e41f4b71Sopenharmony_ci// xxx.ets
51e41f4b71Sopenharmony_ci@Entry
52e41f4b71Sopenharmony_ci@Component
53e41f4b71Sopenharmony_cistruct ScrollBarExample {
54e41f4b71Sopenharmony_ci  private scroller: Scroller = new Scroller()
55e41f4b71Sopenharmony_ci  private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci  build() {
58e41f4b71Sopenharmony_ci    Column() {
59e41f4b71Sopenharmony_ci      Stack({ alignContent: Alignment.End }) {
60e41f4b71Sopenharmony_ci        Scroll(this.scroller) {
61e41f4b71Sopenharmony_ci          Flex({ direction: FlexDirection.Column }) {
62e41f4b71Sopenharmony_ci            ForEach(this.arr, (item: number) => {
63e41f4b71Sopenharmony_ci              Row() {
64e41f4b71Sopenharmony_ci                Text(item.toString())
65e41f4b71Sopenharmony_ci                  .width('80%')
66e41f4b71Sopenharmony_ci                  .height(60)
67e41f4b71Sopenharmony_ci                  .backgroundColor('#3366CC')
68e41f4b71Sopenharmony_ci                  .borderRadius(15)
69e41f4b71Sopenharmony_ci                  .fontSize(16)
70e41f4b71Sopenharmony_ci                  .textAlign(TextAlign.Center)
71e41f4b71Sopenharmony_ci                  .margin({ top: 5 })
72e41f4b71Sopenharmony_ci              }
73e41f4b71Sopenharmony_ci            }, (item:number) => item.toString())
74e41f4b71Sopenharmony_ci          }.margin({ right: 15 })
75e41f4b71Sopenharmony_ci        }
76e41f4b71Sopenharmony_ci        .width('90%')
77e41f4b71Sopenharmony_ci        .scrollBar(BarState.Off)
78e41f4b71Sopenharmony_ci        .scrollable(ScrollDirection.Vertical)
79e41f4b71Sopenharmony_ci        ScrollBar({ scroller: this.scroller, direction: ScrollBarDirection.Vertical,state: BarState.Auto }) {
80e41f4b71Sopenharmony_ci          Text()
81e41f4b71Sopenharmony_ci            .width(20)
82e41f4b71Sopenharmony_ci            .height(100)
83e41f4b71Sopenharmony_ci            .borderRadius(10)
84e41f4b71Sopenharmony_ci            .backgroundColor('#C0C0C0')
85e41f4b71Sopenharmony_ci        }.width(20).backgroundColor('#ededed')
86e41f4b71Sopenharmony_ci      }
87e41f4b71Sopenharmony_ci    }
88e41f4b71Sopenharmony_ci  }
89e41f4b71Sopenharmony_ci}
90e41f4b71Sopenharmony_ci```
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci![en-us_image_0000001232775585](figures/en-us_image_0000001232775585.gif)
94