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