js-components-basic-slider.md 2.9 KB
Newer Older
E
ester.zhou 已提交
1
# slider
Z
zengyawen 已提交
2

E
ester.zhou 已提交
3 4
>  **NOTE**
>
E
ester.zhou 已提交
5
> This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
6

E
ester.zhou 已提交
7
The **\<slider>** component is used to quickly adjust settings, such as the volume and brightness.
E
ester.zhou 已提交
8 9 10


## Child Components
Z
zengyawen 已提交
11 12 13 14

Not supported


E
ester.zhou 已提交
15
## Attributes
Z
zengyawen 已提交
16

E
ester.zhou 已提交
17
In addition to the [universal attributes](../arkui-js/js-components-common-attributes.md), the following attributes are supported.
Z
zengyawen 已提交
18

E
ester.zhou 已提交
19 20 21 22 23 24
| Name| Type| Default Value| Mandatory| Description|
| -------- | -------- | -------- | -------- | -------- |
| min | number | 0 | No| Minimum value of the slider.|
| max | number | 100 | No| Maximum value of the slider.|
| step | number | 1 | No| Step of each slide.|
| value | number | 0 | No| Initial value of the slider.|
E
ester.zhou 已提交
25
| mode<sup>5+</sup> | string | outset | No| Slider style. Available values are as follows:<br>- **outset**: The slider is on the slider track.<br>- **inset**: The slider is in the slider track.|
E
ester.zhou 已提交
26 27
| showsteps<sup>5+</sup> | boolean | false | No| Whether to display slider scales.|
| showtips<sup>5+</sup> | boolean | false | No| Whether a tooltip is displayed to show the percentage value on the slider.|
Z
zengyawen 已提交
28 29


E
ester.zhou 已提交
30
## Styles
Z
zengyawen 已提交
31

E
ester.zhou 已提交
32
In addition to the [universal styles](../arkui-js/js-components-common-styles.md), the following styles are supported.
Z
zengyawen 已提交
33

E
ester.zhou 已提交
34 35 36 37 38
| Name| Type| Default Value| Mandatory| Description|
| -------- | -------- | -------- | -------- | -------- |
| color | &lt;color&gt; | #19000000 | No| Background color of the slider.|
| selected-color | &lt;color&gt; | #ff007dff | No| Selected color of the slider.|
| block-color | &lt;color&gt; | \#ffffff | No| Slider color.|
Z
zengyawen 已提交
39 40


E
ester.zhou 已提交
41
## Events
Z
zengyawen 已提交
42

E
ester.zhou 已提交
43
In addition to the [universal events](../arkui-js/js-components-common-events.md), the following events are supported.
Z
zengyawen 已提交
44

E
ester.zhou 已提交
45 46 47
| Name| Parameter| Description|
| -------- | -------- | -------- |
| change | ChangeEvent | Triggered when the value changes.|
Z
zengyawen 已提交
48

E
ester.zhou 已提交
49 50 51 52 53
**Table 1** ChangeEvent

| Attribute| Type| Description|
| -------- | -------- | -------- |
| value<sup>5+</sup> | number | Current value of the slider.|
E
ester.zhou 已提交
54
| mode<sup>5+</sup> | string | Type of the change event. Available values are as follows:<br>- **start**: The **value** starts to change.<br>- **move**: The **value** is changing with users' dragging.<br>- **end**: The **value** stops changing.<br>- **click**: The **value** changes upon a touch on the slider.|
E
ester.zhou 已提交
55 56 57 58 59


## Example

```html
Z
zengyawen 已提交
60 61
<!-- xxx.hml -->
<div class="container">
E
ester.zhou 已提交
62 63 64
    <slider min="0" max="100" value="{{ value }}" mode="outset" showtips="true"></slider>
    <slider class="" min="0" max="100" value="{{ value }}" step="20" mode="inset"  showtips="true"></slider>
    <slider class="" min="0" max="100" value="{{ value }}" showsteps="true" step="20" mode="inset"  showtips="false"></slider>
Z
zengyawen 已提交
65 66 67
</div>
```

E
ester.zhou 已提交
68
```css
Z
zengyawen 已提交
69 70
/* xxx.css */
.container {
E
ester.zhou 已提交
71 72 73
    flex-direction: column;
    justify-content: center;
    align-items: center;
Z
zengyawen 已提交
74
}
E
ester.zhou 已提交
75 76
slider{
    margin-top: 100px;
Z
zengyawen 已提交
77 78 79
}
```

E
ester.zhou 已提交
80

E
ester.zhou 已提交
81
![slider](figures/slider.png)