1e41f4b71Sopenharmony_ci# swiper 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **\<swiper>** component provides a container that allows users to switch among child components using swipe gestures. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Child Components 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ciAll child components except **\<list>** are supported. 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## Attributes 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description| 18e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 19e41f4b71Sopenharmony_ci| index | number | 0 | No| Index of the child component currently displayed in the container.| 20e41f4b71Sopenharmony_ci| loop | boolean | true | No| Whether to enable looping. | 21e41f4b71Sopenharmony_ci| duration | number | - | No| Duration of the autoplay for child component switching.| 22e41f4b71Sopenharmony_ci| vertical | boolean | false | No| Whether the swipe gesture is performed vertically. A vertical swipe uses the vertical indicator.<br>The value cannot be dynamically updated.| 23e41f4b71Sopenharmony_ci| id | string | - | No| Unique ID of the component.| 24e41f4b71Sopenharmony_ci| style | string | - | No| Style declaration of the component.| 25e41f4b71Sopenharmony_ci| class | string | - | No| Style class of the component, which is used to refer to a style table.| 26e41f4b71Sopenharmony_ci| ref | string | - | No| Reference information of child elements, which is registered with the parent component on **$refs**.| 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci## Events 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci| Name| Parameter| Description| 32e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 33e41f4b71Sopenharmony_ci| change | { index: currentIndex } | Triggered when the index of the currently displayed component changes.| 34e41f4b71Sopenharmony_ci| click | - | Triggered when the component is clicked.| 35e41f4b71Sopenharmony_ci| longpress | - | Triggered when the component is long pressed.| 36e41f4b71Sopenharmony_ci| swipe<sup>5+</sup> | [SwipeEvent](js-lite-common-events.md) | Triggered when a user quickly swipes on the component.| 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci## Styles 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description| 42e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 43e41f4b71Sopenharmony_ci| width | <length> \| <percentage><sup>5+</sup> | - | No| Component width.<br>If this attribute is not set, the default value **0** is used. | 44e41f4b71Sopenharmony_ci| height | <length> \| <percentage><sup>5+</sup> | - | No| Component height.<br>If this attribute is not set, the default value **0** is used. | 45e41f4b71Sopenharmony_ci| padding | <length> | 0 | No| Shorthand attribute to set the padding for all sides.<br>The attribute can have one to four values:<br>- If you set only one value, it specifies the padding for all the four sides.<br>- If you set two values, the first value specifies the top and bottom padding, and the second value specifies the left and right padding.<br>- If you set three values, the first value specifies the top padding, the second value specifies the left and right padding, and the third value specifies the bottom padding.<br>- If you set four values, they respectively specify the padding for top, right, bottom, and left sides (in clockwise order).| 46e41f4b71Sopenharmony_ci| padding-[left\|top\|right\|bottom] | <length> | 0 | No| Left, top, right, and bottom padding.| 47e41f4b71Sopenharmony_ci| margin | <length> \| <percentage><sup>5+</sup> | 0 | No| Shorthand attribute to set the margin for all sides. The attribute can have one to four values:<br>- If you set only one value, it specifies the margin for all the four sides.<br>- If you set two values, the first value specifies the top and bottom margins, and the second value specifies the left and right margins.<br>- If you set three values, the first value specifies the top margin, the second value specifies the left and right margins, and the third value specifies the bottom margin.<br>- If you set four values, they respectively specify the margin for top, right, bottom, and left sides (in clockwise order).| 48e41f4b71Sopenharmony_ci| margin-[left\|top\|right\|bottom] | <length> \| <percentage><sup>5+</sup> | 0 | No| Left, top, right, and bottom margins.| 49e41f4b71Sopenharmony_ci| border-width | <length> | 0 | No| Shorthand attribute to set the margin for all sides.| 50e41f4b71Sopenharmony_ci| border-color | <color> | black | No| Shorthand attribute to set the color for all borders.| 51e41f4b71Sopenharmony_ci| border-radius | <length> | - | No| Radius of round-corner borders.| 52e41f4b71Sopenharmony_ci| background-color | <color> | - | No| Background color.| 53e41f4b71Sopenharmony_ci| opacity<sup>5+</sup> | number | 1 | No| Opacity of an element. The value ranges from **0** to **1**. The value **1** means opaque, and **0** means completely transparent.| 54e41f4b71Sopenharmony_ci| display | string | flex | No| How and whether to display the box containing an element. Available values are as follows:<br>- **flex**: flexible layout<br>- **none**: not rendered| 55e41f4b71Sopenharmony_ci| [left\|top] | <length> \| <percentage><sup>6+</sup> | - | No| Edge of the element.<br>- **left**: left edge position of the element. This attribute defines the offset between the left edge of the margin area of a positioned element and left edge of its containing block.<br>- **top**: top edge position of the element. This attribute defines the offset between the top edge of a positioned element and that of a block included in the element. | 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci## Example 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci```html 62e41f4b71Sopenharmony_ci<!-- xxx.hml --> 63e41f4b71Sopenharmony_ci<swiper class="container" index="{{index}}"> 64e41f4b71Sopenharmony_ci <div class="swiper-item primary-item"> 65e41f4b71Sopenharmony_ci <text>1</text> 66e41f4b71Sopenharmony_ci </div> 67e41f4b71Sopenharmony_ci <div class="swiper-item warning-item"> 68e41f4b71Sopenharmony_ci <text>2</text> 69e41f4b71Sopenharmony_ci </div> 70e41f4b71Sopenharmony_ci <div class="swiper-item success-item"> 71e41f4b71Sopenharmony_ci <text>3</text> 72e41f4b71Sopenharmony_ci </div> 73e41f4b71Sopenharmony_ci</swiper> 74e41f4b71Sopenharmony_ci``` 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci```css 78e41f4b71Sopenharmony_ci/* xxx.css */ 79e41f4b71Sopenharmony_ci.container { 80e41f4b71Sopenharmony_ci left: 0px; 81e41f4b71Sopenharmony_ci top: 0px; 82e41f4b71Sopenharmony_ci width: 454px; 83e41f4b71Sopenharmony_ci height: 454px; 84e41f4b71Sopenharmony_ci} 85e41f4b71Sopenharmony_ci.swiper-item { 86e41f4b71Sopenharmony_ci width: 454px; 87e41f4b71Sopenharmony_ci height: 454px; 88e41f4b71Sopenharmony_ci justify-content: center; 89e41f4b71Sopenharmony_ci align-items: center; 90e41f4b71Sopenharmony_ci} 91e41f4b71Sopenharmony_ci.primary-item { 92e41f4b71Sopenharmony_ci background-color: #007dff; 93e41f4b71Sopenharmony_ci} 94e41f4b71Sopenharmony_ci.warning-item { 95e41f4b71Sopenharmony_ci background-color: #ff7500; 96e41f4b71Sopenharmony_ci} 97e41f4b71Sopenharmony_ci.success-item { 98e41f4b71Sopenharmony_ci background-color: #41ba41; 99e41f4b71Sopenharmony_ci} 100e41f4b71Sopenharmony_ci``` 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci```js 104e41f4b71Sopenharmony_ci/* xxx.js */ 105e41f4b71Sopenharmony_ciexport default { 106e41f4b71Sopenharmony_ci data: { 107e41f4b71Sopenharmony_ci index: 1 108e41f4b71Sopenharmony_ci } 109e41f4b71Sopenharmony_ci} 110e41f4b71Sopenharmony_ci``` 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci 113