未验证 提交 eef60d41 编写于 作者: O openharmony_ci 提交者: Gitee

!13300 翻译完成 11733+11732+11546

Merge pull request !13300 from ester.zhou/C1-0106
......@@ -118,7 +118,7 @@ var subscriber = {
},
};
Notification.subscribe(subscriber, (err, data) => { // This API uses an asynchronous callback to return the result.
Notification.subscribe(subscriber, (err) => { // This API uses an asynchronous callback to return the result.
if (err.code) {
console.error('===>failed to subscribe because ' + JSON.stringify(err));
return;
......@@ -133,19 +133,7 @@ var subscriber = {
##### Enabling Notification
Before publishing a notification, check whether the notification feature is enabled for your application. By default, the feature is disabled. The application calls **Notification.requestEnableNotification** to prompt the user to enable the feature.
```js
Notification.requestEnableNotification() .then((data) => {
console.info('===>requestEnableNotification success');
}).catch((err) => {
console.error('===>requestEnableNotification failed because ' + JSON.stringify(err));
});
```
##### Publishing Notifications
Before publishing a notification, check whether the notification feature is enabled for your application. By default, the feature is disabled. You can enabled it in notification settings.
To publish a notification, create a **NotificationRequest** object and set attributes such as the notification type, title, and content. In the following examples, a normal text notification and a notification containing a **WantAgent** are being published.
......@@ -166,7 +154,7 @@ var notificationRequest = {
}
// Publish the notification.
Notification.publish(notificationRequest) .then((data) => {
Notification.publish(notificationRequest) .then(() => {
console.info('===>publish promise success req.id : ' + notificationRequest.id);
}).catch((err) => {
console.error('===>publish promise failed because ' + JSON.stringify(err));
......@@ -235,7 +223,7 @@ var notificationRequest = {
}
// Publish the notification.
Notification.publish(notificationRequest) .then((data) => {
Notification.publish(notificationRequest) .then(() => {
console.info('===>publish promise success req.id : ' + notificationRequest.id);
}).catch((err) => {
console.error('===>publish promise failed because ' + JSON.stringify(err));
......
......@@ -35,6 +35,8 @@ prompt.showToast({
});
```
![en-us_image_0001](figures/en-us_image_0001.gif)
## ShowToastOptions
Describes the options for showing the toast.
......@@ -43,9 +45,9 @@ Describes the options for showing the toast.
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| message | string| Yes | Text to display. |
| message | string | Yes | Text to display. |
| duration | number | No | Duration that the toast will remain on the screen. The default value is 1500 ms. The value range is 1500 ms to 10000 ms. If a value less than 1500 ms is set, the default value is used. If the value greater than 10000 ms is set, the upper limit 10000 ms is used.|
| bottom | string\| number | No | Distance between the toast border and the bottom of the screen. |
| bottom | string\| number | No | Distance between the toast border and the bottom of the screen. |
## prompt.showDialog
......@@ -92,6 +94,8 @@ prompt.showDialog({
})
```
![en-us_image_0002](figures/en-us_image_0002.gif)
## prompt.showDialog
showDialog(options: ShowDialogOptions, callback: AsyncCallback<ShowDialogSuccessResponse>):void
......@@ -132,6 +136,8 @@ prompt.showDialog({
});
```
![en-us_image_0004](figures/en-us_image_0004.gif)
## ShowDialogOptions
Describes the options for showing the dialog box.
......@@ -140,8 +146,8 @@ Describes the options for showing the dialog box.
| Name | Type | Mandatory | Description |
| ------- | ---------------------------------------- | ---- | ---------------------------------------- |
| title | string| No | Title of the dialog box. |
| message | string| No | Text body. |
| title | string | No | Title of the dialog box. |
| message | string | No | Text body. |
| buttons | Array | No | Array of buttons in the dialog box. The array structure is **{text:'button', color: '\#666666'}**. Up to three buttons are supported. The first button is of the **positiveButton** type, the second is of the **negativeButton** type, and the third is of the **neutralButton** type.|
## ShowDialogSuccessResponse
......@@ -170,7 +176,6 @@ Shows an action menu. This API uses a callback to return the result asynchronous
| options | [ActionMenuOptions](#actionmenuoptions) | Yes | Action menu options. |
| callback | AsyncCallback<[ActionMenuSuccessResponse](#actionmenusuccessresponse)> | Yes | Callback used to return the action menu response result.|
**Example**
```js
......@@ -195,6 +200,8 @@ prompt.showActionMenu({
})
```
![en-us_image_0005](figures/en-us_image_0005.gif)
## prompt.showActionMenu
showActionMenu(options: ActionMenuOptions): Promise<ActionMenuSuccessResponse>
......@@ -238,6 +245,8 @@ prompt.showActionMenu({
console.info('showActionMenu error: ' + err);
})
```
![en-us_image_0006](figures/en-us_image_0006.gif)
## ActionMenuOptions
Describes the options for showing the action menu.
......@@ -246,8 +255,8 @@ Describes the options for showing the action menu.
| Name | Type | Mandatory | Description |
| ------- | ---------------------------------------- | ---- | ---------------------------------------- |
| title | string| No | Title of the text to display. |
| buttons | Array<[Button](#button)> | Yes | Array of menu item buttons. The array structure is **{text:'button', color: '\#666666'}**. Up to six buttons are supported. If there are more than six buttons, extra buttons will not be displayed.|
| title | string | No | Title of the text to display. |
| buttons | Array<[Button](#button)> | Yes | Array of menu item buttons. The array structure is **{text:'button', color: '\#666666'}**. Up to six buttons are supported. If there are more than six buttons, extra buttons will not be displayed.|
## ActionMenuSuccessResponse
......@@ -267,5 +276,5 @@ Describes the menu item button in the action menu.
| Name | Type | Mandatory | Description |
| ----- | ---------------------------------------- | ---- | ------- |
| text | string| Yes | Button text.|
| color | string| Yes | Text color of the button.|
| text | string | Yes | Button text.|
| color | string | Yes | Text color of the button.|
......@@ -90,7 +90,7 @@ Generates a URL containing image display information.
</div>
```
```js
```css
// xxx.js
export default {
handleClick() {
......
# Universal Methods
> **NOTE**
>
> This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
After a component is assigned the **id** attribute, you can use the ID to obtain the component objects and call functions.
## animate
animate( keyframes: Keyframes, options: Options): void
- Name
- Parameters
| Name | Type | Mandatory | Description |
| --------- | --------- | --------- | ------------------------------------------------------------ |
| --------- | --------- | --------- | ------------------------------------------------------------ |
| keyframes | keyframes | Yes | Sets the animation style. |
| options | Options | Yes | Array of objects used to set animation attributes. For details, see Options. |
**Table 1** keyframes
**Table 1** keyframes
| Attribute | Type | Description |
| --------- | ------------- | ------------------------------------------------------------ |
| --------- | ------------- | ------------------------------------------------------------ |
| frames | Array\<Style> | Array of objects used to set animation attributes. For details about style attributes, see Style attributes. |
**Table 2** Style attributes
| Name | Type | Default Value | Description |
| ------------------ | ---------------------------------------------- | --------------- | ------------------------------------------------------------ |
| ------------------ | ---------------------------------------------- | --------------- | ------------------------------------------------------------ |
| width | number | - | Width set for the component during playback of the animation. |
| height | number | - | Height set for the component during playback of the animation. |
| height | number | - | Height set for the component during playback of the animation. |
| backgroundColor | \<color> | none | Background color set for the component during playback of the animation. |
| opacity | number | 1 | Opacity set for the component. The value ranges from **0** to **1**. |
| opacity | number | 1 | Opacity set for the component. The value ranges from **0** to **1**. |
| backgroundPosition | string | - | The value format is **x y**, in percentage or pixels.<br>The first value indicates the horizontal position, and the second value indicates the vertical position.<br>If only one value is specified, the other value is **50%** by default. |
| transformOrigin | string | 'center center' | Origin position of the transformed element.<br>The first value indicates the x-axis position. The value can be **left**, **center**, **right**, a length, or a percentage.<br>The second value indicates the y-axis position. The value can be **top**, **center**, **bottom**, a length, or a percentage. |
| transform | [Transform](js-components-common-animation.md) | - | Transformation type set for a transformed element. |
| offset | number | - | The value of **offset** must be within (0.0,1.0] and sorted in ascending order if it is provided.<br>If there are only two frames, **offset** can be left empty.<br>If there are more than two frames, **offset** is mandatory. |
**Table 3** Options description
| Name | Type | Default Value | Description |
| ----------- | ---------------- | ------------- | ------------------------------------------------------------ |
| duration | number | 0 | Duration for playing the animation, in milliseconds. |
| easing | string | linear | Time curve of the animation. For details about the supported types, see Available values of the easing attribute. |
| easing | string | linear | Time curve of the animation. For details about the supported types, see **Available values of the easing attribute**. |
| delay | number | 0 | Delay for the animation start. The default value indicates no delay. |
| iterations | number \| string | 1 | Number of times the animation will be played. **number** indicates a fixed number of playback operations, and **Infinity** indicates an unlimited number of playback operations. |
| iterations | number \| string | 1 | Number of times the animation will be played. **number** indicates a fixed number of playback operations, and **Infinity** indicates an unlimited number of playback operations. |
| direction<sup>6+</sup> | string | normal | Mode of playing the animation. <br>- **normal**: Plays the animation in forward loop mode. <br>- **reverse**: Plays the animation in reverse loop mode. <br>- **alternate**: Plays the animation in alternating loop mode. When the animation is played for an odd number of times, the playback is in forward direction. When the animation is played for an even number of times, the playback is in backward direction. <br>- **alternate-reverse**: Plays the animation in reverse-alternating loop mode. When the animation is played for an odd number of times, the playback is in backward direction. When the animation is played for an even number of times, the playback is in forward direction. |
| fill | string | none | Start and end styles of the animation. <br>- **none**: No style is applied to the target before or after the animation is executed. <br>- **forwards**: The target keeps the state at the end of the animation (defined in the last key frame) after the animation is executed. <br>- **backwards**<sup>6+</sup>: The animation uses the value defined in the first key frame during the **animation-delay**. When **animation-direction** is set to **normal** or **alternate**, the value in the **from** key frame is used. When **animation-direction** is set to **reverse** or **alternate-reverse**, the value in the **to** key frame is used. <br>- **both**<sup>6+</sup>: The animation follows the **forwards** and **backwards** rules. |
| fill | string | none | Start and end styles of the animation. <br>- **none**: No style is applied to the target before or after the animation is executed. <br>- **forwards**: The target keeps the state at the end of the animation (defined in the last key frame) after the animation is executed. <br>- **backwards**<sup>6+</sup>: The animation uses the value defined in the first key frame during the **animation-delay**. When **animation-direction** is set to **normal** or **alternate**, the value in the **from** key frame is used. When **animation-direction** is set to **reverse** or **alternate-reverse**, the value in the **to** key frame is used. <br>- **both**<sup>6+</sup>: The animation follows the **forwards** and **backwards** rules. |
**Table 4** Available values of the easing attribute
| Type | Description |
| ----------------------------------------- | ------------------------------------------------------------ |
| linear | The animation speed keeps unchanged. |
| ease-in | The animation starts at a low speed. **cubic-bezier(0.42, 0.0, 1.0, 1.0)**. |
| ease-out | The animation ends at a low speed. **cubic-bezier(0.0, 0.0, 0.58, 1.0)**. |
| ease-in-out | The animation starts and ends at a low speed. **cubic-bezier(0.42, 0.0, 0.58, 1.0)**. |
| ease-in-out | The animation starts and ends at a low speed. **cubic-bezier(0.42, 0.0, 0.58, 1.0)**. |
| friction | Damping curve, **cubic-bezier(0.2, 0.0, 0.2, 1.0)**. |
| extreme-deceleration | Extreme deceleration curve, **cubic-bezier(0.0, 0.0, 0.0, 1.0)**. |
| extreme-deceleration | Extreme deceleration curve, **cubic-bezier(0.0, 0.0, 0.0, 1.0)**. |
| sharp | Sharp curve, **cubic-bezier(0.33, 0.0, 0.67, 1.0)**. |
| rhythm | Rhythm curve, **cubic-bezier(0.7, 0.0, 0.2, 1.0)**. |
| rhythm | Rhythm curve, **cubic-bezier(0.7, 0.0, 0.2, 1.0)**. |
| smooth | Smooth curve, **cubic-bezier(0.4, 0.0, 0.4, 1.0)**. |
| cubic-bezier(x1, y1, x2, y2) | You can customize an animation speed curve in the **cubic-bezier()** function. The x and y values of each input parameter must be between 0 and 1. |
| steps(number, step-position)<sup>6+</sup> | Step curve.<br>The **number** must be set and only an integer is supported.<br>**step-position** is optional. It can be set to **start** or **end**. The default value is **end**. |
- Return values
- Return value
The **animation** attributes are as follows.
| Attribute | Type | Description |
| --------- | ------- | ------------------------------------------------------------ |
| --------- | ------- | ------------------------------------------------------------ |
| finished | boolean | Read-only attribute, which indicates whether the animation playback is complete. |
| pending | boolean | Read-only attribute, which indicates whether the animation is waiting for the completion of other asynchronous operations (for example, start an animation with a delay). |
| playState | string | Read-write attribute, which indicates the playback status of the animation: <br>- **idle**: The animation is not running (playback ended or not started). <br>- **running**: The animation is running. <br>- **paused**: The animation is paused. <br>- **finished**: Animation playback ends. |
| startTime | number | Read-write attribute, which indicates the animation start time. This attribute is similar to **delay** in the **options** attribute. |
Methods for animation
Methods for animation
| Method | Parameter | Description |
| ------- | --------- | ------------------------------- |
| ------- | --------- | ------------------------------- |
| play | - | Plays the animation. |
| finish | - | Ends the animation. |
| finish | - | Ends the animation. |
| pause | - | Pauses the animation. |
| cancel | - | Cancels the animation. |
| reverse | - | Plays the animation in reverse. |
Events for animation
| Event | Description |
| ------- | ----------------------------------- |
| ------- | ----------------------------------- |
| start<sup>6+</sup> | The animation starts. |
| cancel | The animation is forcibly canceled. |
| cancel | The animation is forcibly canceled. |
| finish | The animation playback is complete. |
| repeat | The animation repeats. |
| repeat | The animation repeats. |
- Example
```
<!-- xxx.hml -->
<div class="container">
<div id="idName" class="box"></div>
<div class="buttonBox">
<button @click="start">
start
</button>
<button @click="cancel">
cancels
</button>
</div>
```html
<!-- xxx.hml -->
<div class="container">
<div id="idName" class="box"></div>
<div class="buttonBox">
<button @click="start">
start
</button>
<button @click="cancel">
cancel
</button>
</div>
```
```
```
/* xxx.css */
......@@ -209,19 +196,17 @@ getBoundingClientRect(): \<Rect>
Obtains the size of the element and its position relative to the window.
- Return values
**Table 5** Rect attributes<sup>6+</sup>
- Return value
**Table 5** Rect<sup>6+</sup>
| Attribute | Type | Description |
| --------- | ------ | ------------------------------------------------------------ |
| --------- | ------ | ------------------------------------------------------------ |
| width | number | Width of an element. |
| height | number | Height of an element. |
| left | number | Offset between the left boundary of the element and the window. |
| top | number | Offset between the upper boundary of the element and the window. |
- Example
```
......@@ -232,37 +217,31 @@ Obtains the size of the element and its position relative to the window.
## createIntersectionObserver
createIntersectionObserver(param?: ObserverParam):Observer
createIntersectionObserver(param?: ObserverParam): Observer
Gets notified of the visibility of an element on the current page.
- Name
- Parameters
| Name | Type | Mandatory | Description |
| ----- | ------------- | --------- | ------------------------------ |
| ----- | ------------- | --------- | ------------------------------ |
| param | ObserverParam | - | Obtains the observer callback. |
**Table 6** ObserverParam attributes<sup>6+</sup>
**Table 6** ObserverParam<sup>6+</sup>
| Attribute | Type | Description |
| --------- | ------------- | ------------------------------------------------------------ |
| --------- | ------------- | ------------------------------------------------------------ |
| ratios | Array\<number> | When the component is out of the range or is less than the range, the observer callback is triggered. |
- Return values
- Return value
**Table 7** Methods supported by the Observer object<sup>6+</sup>
| Name | Parameter | Description |
| --------- | ------------------ | ------------------------------------------------------------ |
| --------- | ------------------ | ------------------------------------------------------------ |
| observe | callback: function | Subscribes to events of the observed object. The callback method is called when the value is greater than or less than the threshold. |
| unobserve | - | Unsubscribes from events of the observed object. |
- Example
```
......
# Universal Styles
> **NOTE**
> Universal attributes are supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
>
> Universal styles are supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
You can set component appearance in the **style** attribute or **.css** files.
You can set universal styles for components in the **style** attribute or **.css** files.
......@@ -40,6 +41,7 @@ You can set component appearance in the **style** attribute or **.css** files.
| box-shadow<sup>5+</sup> | string | 0 | Shadow style of the current component. The value consists of the horizontal position (mandatory), vertical position (mandatory), fuzzy radius (optional, default value: **0**), extension distance (optional, default value: **0**), and color (optional, default value: **black**) of the shadow. Example:<br>- box-shadow :10px 20px 5px 10px #888888<br>- box-shadow :100px 100px 30px red<br>- box-shadow :-100px -100px 0px 40px |
| filter<sup>5+</sup> | string | - | Radius of the blur area within the component layout. If the radius is not set, the default value **0** (no blur area) is used. Percentage values are not supported.Syntax: **filter: blur(px)**<br>Example:<br>- filter: blur(10px) |
| backdrop-filter<sup>5+</sup> | string | - | Radius of the background blur area within the component layout. If the radius is not set, the default value **0** (no background blur) is used. Percentage values are not supported.Syntax: **backdrop-filter: blur(px)**<br>Example:<br>- backdrop-filter: blur(10px) |
| window-filter<sup>5+</sup> | string | - | Syntax: window-filter: blur(percent), style<sup>5+</sup><br>Blur degree and style for windows within the component layout. If this style is not set, the default value **0%** (no blur area) is used. Different blur degrees and styles for multiple blur areas are not supported. Available values of **style** are as follows: small_light (default value), medium_light, large_light, xlarge_light, small_dark, medium_dark, large_dark, xlarge_dark<br>Example:<br>- window-filter: blur(50%)<br>- window-filter: blur(10%), large_light |
| opacity | number | 1 | Opacity of an element. The value ranges from **0** to **1**. The value **1** means opaque, and **0** means completely transparent. |
| display | string | flex | How and whether to display the box containing an element. Available values are as follows:<br>- **flex**: flexible layout.<br>- **none**: The element is hidden. |
| visibility | string | visible | Whether to display an element. Invisible borders occupy layout space. (To remove the borders, set the **display** attribute to **none**.) Available values are as follows:<br>- **visible**: The element is visible.<br>- **hidden**: The element is hidden but still takes up space.NOTE:If both **visibility** and **display** are set, only **display** takes effect. |
......@@ -64,5 +66,7 @@ You can set component appearance in the **style** attribute or **.css** files.
| border-image-repeat<sup>7+</sup> | string | stretch | How the border image fills the border box.<br/>- **stretch**: stretches the image to fill the border box.<br/>- **repeat**: tiles the image to fill the border box.<br/>- **round**: tiles the image to fill the border box. When the image cannot be tiled for an integer number of times, it can be scaled based on the site requirements. |
| border-image<sup>7+</sup> | string | - | Shorthand attribute. The options are as follows:<br>- Attributes of the image border. The parameters include **border-image-source**, **border-image-slice**, **border-image-width**, **border-image-outset**, and **border-image-repeat**, respectively meaning the padding, width of the border image, how far the border image can extend beyond the border box, and how the border image fills the border box. The default values are used if the parameters are not set.<br>Syntax reference:<'border-image-source'> \|\| <'border-image-slice'> [ <'border-image-width'> <br>- Gradient color border.<br>Example:<br>border-image: linear-gradient(red, yellow) 10px |
> ![img](https://gitee.com/openharmony/docs/raw/OpenHarmony-3.1-Release/en/application-dev/public_sys-resources/icon-note.gif) **NOTE:** The above-mentioned common styles are not mandatory.
> **NOTE**
>
> The aforementioned universal styles are not mandatory.
......@@ -259,7 +259,7 @@ export default {
```
```js
// xxx.js
<!-- xxx.js -->
import router from '@ohos.router';
export default {
data: {
......@@ -274,7 +274,7 @@ export default {
```
```css
/* xxx.css */
<!-- xxx.css -->
.container {
flex-direction: column;
justify-content: center;
......@@ -316,6 +316,7 @@ export default {
}
```
2. Page2
......@@ -328,7 +329,7 @@ export default {
```
```js
// xxx.js
<!-- xxx.js -->
import router from '@ohos.router';
export default {
data: {
......@@ -338,10 +339,11 @@ export default {
router.back()
}
}
```
```css
/* xxx.css */
```
```css
<!-- xxx.css -->
.container {
flex-direction: column;
justify-content: center;
......
......@@ -35,15 +35,13 @@ export default {
console.log("Component created.")
},
onAttached() {
this.value = "Load the component."
},
onDetached() {
this.value = ""
console.log("Component loaded.")
},
onPageShow() {
onShow() {
console.log ("Page displayed.")
},
onPageHide() {
onHide() {
console.log ("Page hidden.")
}
}
......
......@@ -2,8 +2,9 @@
The **<animateMotion\>** component is used to define the animation along a path.
>![](../../public_sys-resources/icon-note.gif) **NOTE:**
>This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
> **NOTE**
>
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
## Required Permissions
......@@ -36,7 +37,7 @@ The **animate** attributes \(**values** does not take effect\) and the attrib
<path fill="none" stroke="blue" stroke-width="3" d="m40,130 c0,-100 160,100 160,0 c0,-100 -160,100 -160,0 z"></path>
<path fill="none" stroke="blue" stroke-width="3" d="m40,200 c0,-100 160,100 160,0 c0,-100 -160,100 -160,0 z"></path>
<path fill="red" d="M-5,-5 L10,0 L-5,5 L0,0 Z">
<animateMotion dur="2000" repeatCount="indefinite" rotate="auto" keyPoints="0;0.2;0.4;0.6;0.8;1" path="m40,60 c0,-100 160,160,100 160,0 c0,-100,-160,100 -160,0 z">
<animateMotion dur="2000" repeatCount="indefinite" rotate="auto" keyPoints="0;0.2;0.4;0.6;0.8;1" path="m40,60 c0,-100 160,100 160,0 c0,-100 -160,100 -160,0 z">
</animateMotion>
</path>
<path fill="red" d="M-5,-5 L10,0 L-5,5 L0,0 Z">
......
......@@ -4,8 +4,9 @@ The **<animateTransform\>** component is used to apply a transform animation a
<circle\>, <ellipse\>, <line\>, <path\>, <polygon\>, <polyline\>, <rect\>, <text\>
>![](../../public_sys-resources/icon-note.gif) **NOTE:**
>This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
> **NOTE**
>
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
## Required Permissions
......@@ -182,6 +183,7 @@ Involved component example
dur="3s" repeatCount="indefinite"></animateTransform>
</rect>
<text x="20" y="700" fill="#D2691E" font-size="40">
animate-transform
<animateTransform attributeName="transform" attributeType="XML" type="translate" from="0" to="300"
dur="3s" repeatCount="indefinite"></animateTransform>
</text>
......
......@@ -97,9 +97,9 @@ Combination of **\<textpath>** and **\<tspan>**
<!-- xxx.hml -->
<div class="container">
<svg fill="#00FF00" x="50">
<path d="M40,760 Q360,760 360,580 Q360,440 200,440 Q40,440 40,560 Q40,680 180,680 Q280,680 300,600" stroke="red" fill="none"></path>
<path d="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" stroke="red" fill="none"></path>
<text>
<textpath fill="#D2691E" path="M40,760 Q360,760 360,580 Q360,440 200,440 Q40,440 40,560 Q40,680 180,680 Q280,680 300,600"font-size="30px" stroke="black" stroke-width="1" >
<textpath fill="#D2691E" path="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" font-size="30px" stroke="black" stroke-width="1" >
This is TextPath.
<tspan font-size="20px" fill="red">This is tspan onTextPath.</tspan>
<tspan font-size="30px">Let's play.</tspan>
......@@ -117,11 +117,11 @@ Combination of **\<textpath>** and **\<tspan>**
<!-- xxx.hml -->
<div class="container">
<svg fill="#00FF00" x="50">
<path d="M40,1160 Q360,1160 360,980 Q360,840 200,840 Q40,840 40,960 Q40,1080 180,1080 Q280,1080 300,1000" stroke="red" fill="none">
<path d="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" stroke="red" fill="none">
</path>
<!-- Value percentage -->
<text>
<textpath fill="#D2691E" path="M40,1160 Q360,1160 360,980 Q360,840 200,840 Q40,840 40,960 Q40,1080 180,1080 Q280,1080 300,1000" font-size="30px">
<textpath fill="#D2691E" path="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" font-size="30px">
This is TextPath.
<tspan x="50" fill="blue">This is first tspan.</tspan>
<tspan x="50%">This is second tspan.</tspan>
......@@ -172,10 +172,10 @@ Attribute animation of the **\<textPath>** and **\<tspan>** in combination
<!-- xxx.hml -->
<div class="container">
<svg fill="#00FF00">
<path d="M40,1160 Q360,1160 360,980 Q360,840 200,840 Q40,840 40,960 Q40,1080 180,1080 Q280,1080 300,1000" stroke="red" fill="none">
<path d="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" stroke="red" fill="none">
</path>
<text>
<textpath fill="#D2691E" path="M40,1160 Q360,1160 360,980 Q360,840 200,840 Q40,840 40,960 Q40,1080 180,1080 Q280,1080 300,1000" font-size="30px">
<textpath fill="#D2691E" path="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" font-size="30px">
This is TextPath.
<tspan x="50" fill="blue">
tspan attribute x|rotate
......@@ -209,11 +209,11 @@ Attribute animation of the **\<textPath>** and **\<tspan>** in combination
<!-- xxx.hml -->
<div class="container">
<svg fill="#00FF00">
<path d="M40,1560 Q360,1560 360,1380 Q360,1240 200,1240 Q40,1240 40,1360 Q40,1480 180,1480 Q280,1480 300,1400" stroke="red"
<path d="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" stroke="red"
fill="none">
</path>
<text>
<textpath fill="#D2691E" path="M40,1560 Q360,1560 360,1380 Q360,1240 200,1240 Q40,1240 40,1360 Q40,1480 180,1480 Q280,1480 300,1400" font-size="30px">
<textpath fill="#D2691E" path="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" font-size="30px">
This is TextPath.
<tspan dx="20" fill="blue">
tspan attribute fill|fill-opacity
......@@ -247,11 +247,11 @@ Attribute animation of the **\<textPath>** and **\<tspan>** in combination
<!-- xxx.hml -->
<div class="container">
<svg fill="#00FF00">
<path d="M40,1960 Q360,1960 360,1780 Q360,1640 200,1640 Q40,1640 40,1760 Q40,1880 180,1880 Q280,1880 300,1800" stroke="red"
<path d="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" stroke="red"
fill="none">
</path>
<text>
<textpath fill="#D2691E" path="M40,1960 Q360,1960 360,1780 Q360,1640 200,1640 Q40,1640 40,1760 Q40,1880 180,1880 Q280,1880 300,1800" font-size="30px">
<textpath fill="#D2691E" path="M40,360 Q360,360 360,180 Q360,40 200,40 Q40,40 40,160 Q40,280 180,280 Q280,280 300,200" font-size="30px">
This is TextPath.
<tspan dx="20" fill="blue">
tspan attribute stroke
......
......@@ -18,28 +18,28 @@ Circle(options?: {width?: string | number, height?: string | number})
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| width | string \| number | No| Width of the circle.<br>Default value: **0**|
| height | string \| number | No| Height of the circle.<br>Default value: **0**|
| Name| Type| Mandatory| Default Value | Description|
| -------- | -------- | -------- | -------- | -------- |
| width | string \| number | No| 0 | Width of the circle. |
| height | string \| number | No| 0 | Height of the circle. |
## Attributes
In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.
| Name| Type| Description|
| -------- | -------- | -------- |
| fill | [ResourceColor](ts-types.md#resourcecolor8) | Color of the fill area.<br>Default value: **Color.Black**|
| fillOpacity | number \| string \| [Resource](ts-types.md#resource)| Opacity of the fill area.<br>Default value: **1**|
| stroke | [ResourceColor](ts-types.md#resourcecolor8) | Stroke color. If this attribute is not set, the component does not have any stroke.|
| strokeDashArray | Array&lt;Length&gt; | Stroke dashes.<br>Default value: **[]** |
| strokeDashOffset | number \| string | Offset of the start point for drawing the stroke.<br>Default value: **0**|
| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | Cap style of the stroke.<br>Default value: **LineCapStyle.Butt**|
| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | Join style of the stroke.<br>Default value: **LineJoinStyle.Miter**|
| strokeMiterLimit | number \| string | Limit on the ratio of the miter length to the value of **strokeWidth** used to draw a miter join.<br>Default value: **4**<br>**NOTE**<br>This attribute does not take effect for the **\<Circle>** component, because it does not have a miter join.|
| strokeOpacity | number \| string \| [Resource](ts-types.md#resource)| Stroke opacity.<br>Default value: **1**<br>**NOTE**<br>The value range is [0.0, 1.0]. If the set value is less than 0.0, **0.0** will be used. If the set value is greater than 1.0, **1.0** will be used.|
| strokeWidth | Length | Stroke width.<br>Default value: **1**|
| antiAlias | boolean | Whether anti-aliasing is enabled.<br>Default value: **true**|
| Name| Type| Default Value | Description|
| -------- | -------- | -------- | -------- |
| fill | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | Color of the fill area. |
| fillOpacity | number \| string \| [Resource](ts-types.md#resource)| 1 | Opacity of the fill area. |
| stroke | [ResourceColor](ts-types.md#resourcecolor8) | - | Stroke color. If this attribute is not set, the component does not have any stroke.|
| strokeDashArray | Array&lt;Length&gt; | [] | Stroke dashes. |
| strokeDashOffset | number \| string | 0 | Offset of the start point for drawing the stroke. |
| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | Cap style of the stroke. |
| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | Join style of the stroke. |
| strokeMiterLimit | number \| string | 4 | Limit on the ratio of the miter length to the value of **strokeWidth** used to draw a miter join.<br>**NOTE**<br>This attribute does not take effect for the **\<Circle>** component, because it does not have a miter join. |
| strokeOpacity | number \| string \| [Resource](ts-types.md#resource)| 1 | Stroke opacity.<br>**NOTE**<br>The value range is [0.0, 1.0]. If the set value is less than 0.0, **0.0** will be used. If the set value is greater than 1.0, **1.0** will be used. |
| strokeWidth | Length | 1 | Stroke width. |
| antiAlias | boolean | true | Whether anti-aliasing is enabled. |
## Example
......
......@@ -18,10 +18,10 @@ ellipse(options?: {width?: string | number, height?: string | number})
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| width | string \| number | No| Width.<br>Default value: **0**|
| height | string \| number | No| Height.<br>Default value: **0**|
| Name| Type| Mandatory| Default Value | Description|
| -------- | -------- | -------- | -------- | -------- |
| width | string \| number | No| 0 | Width. |
| height | string \| number | No| 0 | Height. |
## Attributes
......
......@@ -17,11 +17,11 @@ Path(value?: { width?: number | string; height?: number | string; commands?: str
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------- | ---- | ----------------------------------- |
| width | number \| string | No | Width of the rectangle where the path is located.<br>Default value: **0** |
| height | number \| string | No | Height of the rectangle where the path is located.<br>Default value: **0** |
| commands | string | No | Command for drawing the path.<br>Default value: **''**|
| Name | Type | Mandatory| Default Value | Description |
| -------- | ---------------- | ---- | ----------------------------------- | ----------------------------------- |
| width | number \| string | No | 0 | Width of the rectangle where the path is located. |
| height | number \| string | No | 0 | Height of the rectangle where the path is located. |
| commands | string | No | '' | Command for drawing the path. |
## Attributes
......
......@@ -153,12 +153,12 @@ struct ShapeExample {
@Entry
@Component
struct ShapeMeshExample {
@State columnVal: number = 0
@State rowVal: number = 0
@State count: number = 0
@State verts: Array<number> = []
@State shapeWidth: number = 600
@State shapeHeight: number = 600
@State columnVal: number = 0;
@State rowVal: number = 0;
@State count: number = 0;
@State verts: Array<number> = [];
@State shapeWidth: number = 600;
@State shapeHeight: number = 600;
build() {
Column() {
......@@ -187,34 +187,34 @@ struct ShapeMeshExample {
.height(this.shapeHeight + 'px')
// The mesh distortion effect is displayed when the component is touched.
.onTouch((event: TouchEvent) => {
var touchX = event.touches[0].x * 2
var touchY = event.touches[0].y * 2
this.columnVal = 20
this.rowVal = 20
this.count = (this.columnVal + 1) * (this.rowVal + 1)
var orig = [this.count * 2]
var index = 0
var touchX = event.touches[0].x * 2;
var touchY = event.touches[0].y * 2;
this.columnVal = 20;
this.rowVal = 20;
this.count = (this.columnVal + 1) * (this.rowVal + 1);
var orig = [this.count * 2];
var index = 0;
for (var i = 0; i <= this.rowVal; i++) {
var fy = this.shapeWidth * i / this.rowVal
var fy = this.shapeWidth * i / this.rowVal;
for (var j = 0; j <= this.columnVal; j++) {
var fx = this.shapeWidth * j / this.columnVal
orig[index * 2 + 0] = this.verts[index * 2 + 0] = fx
orig[index * 2 + 1] = this.verts[index * 2 + 1] = fy
var fx = this.shapeWidth * j / this.columnVal;
orig[index * 2 + 0] = this.verts[index * 2 + 0] = fx;
orig[index * 2 + 1] = this.verts[index * 2 + 1] = fy;
index++;
}
}
for (var k = 0; k < this.count * 2; k += 2) {
var dx = touchX - orig[k + 0]
var dy = touchY - orig[k + 1]
var dd = dx * dx + dy * dy
var d = Math.sqrt(dd)
var pull = 80000 / (dd * d)
var dx = touchX - orig[k + 0];
var dy = touchY - orig[k + 1];
var dd = dx * dx + dy * dy;
var d = Math.sqrt(dd);
var pull = 80000 / (dd * d);
if (pull >= 1) {
this.verts[k + 0] = touchX
this.verts[k + 1] = touchY
this.verts[k + 0] = touchX;
this.verts[k + 1] = touchY;
} else {
this.verts[k + 0] = orig[k + 0] + dx * pull
this.verts[k + 1] = orig[k + 1] + dy * pull
this.verts[k + 0] = orig[k + 0] + dx * pull;
this.verts[k + 1] = orig[k + 1] + dy * pull;
}
}
})
......
......@@ -77,6 +77,23 @@ struct AnimateToExample {
}
this.flag = !this.flag
})
Button('change rotate angle')
.margin(50)
.rotate({ x: 0, y: 0, z: 1, angle: this.rotateAngle })
.onClick(() => {
animateTo({
duration: 1200,
curve: Curve.Friction,
delay: 500,
iterations: -1, // The value -1 indicates that the animation is played for an unlimited number of times.
playMode: PlayMode.AlternateReverse,
onFinish: () => {
console.info('play end')
}
}, () => {
this.rotateAngle = 90
})
})
}.width('100%').margin({ top: 5 })
}
}
......
......@@ -29,14 +29,13 @@ The ES6 syntax is supported.
## Objects
- Application objects
| Name | Type | Description |
| Name | Type | Description |
| -------- | -------- | -------- |
| $def | Object | Object that is exposed in the app.js file and obtained by `this.$app.$def`.<br/>> **NOTE**<br/>> Application objects do not support data binding. Data update should be triggered on the UI. |
Example
```
```js
// app.js
export default {
onCreate() {
......@@ -56,8 +55,7 @@ The ES6 syntax is supported.
};
```
```
```js
// index.js
export default {
data: {
......@@ -97,8 +95,7 @@ The ES6 syntax is supported.
Example
```
```js
// index.js
export default {
data: {
......@@ -149,7 +146,7 @@ The ES6 syntax is supported.
Example
```
```js
this.$rootElement().scrollTo({position: 0})
this.$rootElement().scrollTo({id: 'id', duration: 200, timingFunction: 'ease-in', complete: ()=>void})
```
......@@ -158,24 +155,22 @@ The ES6 syntax is supported.
## Obtaining a DOM Element
1. Use `$refs` to obtain a DOM element.
```
```html
<!-- index.hml -->
<div class="container">
<image-animator class="image-player" ref="animator" images="{{images}}" duration="1s" onclick="handleClick"></image-animator>
</div>
```
```
```js
// index.js
export default {
data: {
images: [
{ src: '/common/frame1.png' },
{ src: '/common/frame2.png' },
{ src: '/common/frame3.png' },
],
{ src: '/common/frame3.png' }
]
},
handleClick() {
const animator = this.$refs.animator; // Obtain the DOM element whose $refs attribute is animator.
......@@ -193,23 +188,22 @@ The ES6 syntax is supported.
2. Call `$element` to obtain a DOM element.
```
```html
<!-- index.hml -->
<div class="container" style="width:500px;height: 700px; margin: 100px;">
<image-animator class="image-player" id="animator" images="{{images}}" duration="1s" onclick="handleClick"></image-animator>
</div>
```
```
```js
// index.js
export default {
data: {
images: [
{ src: '/common/frame1.png' },
{ src: '/common/frame2.png' },
{ src: '/common/frame3.png' },
],
{ src: '/common/frame3.png' }
]
},
handleClick() {
const animator = this.$element('animator'); // Obtain the DOM element whose ID is animator.
......@@ -231,7 +225,7 @@ The ES6 syntax is supported.
The following shows files of the root page:
```
```html
<!-- root.hml -->
<element name='parentComp' src='../../common/component/parent/parent.hml'></element>
<div class="container">
......@@ -242,8 +236,7 @@ The following shows files of the root page:
</div>
```
```
```js
// root.js
export default {
data: {
......@@ -256,26 +249,25 @@ export default {
Customize the parent component.
```
```html
<!-- parent.hml -->
<element name='childComp' src='../child/child.hml'></element>
<div class="item" onclick="textClicked">
<text class="text-style" onclick="parentClicked">Click this parent component</text>
<text class="text-style" if="{{show}}">Hello parent component!</text>
<text class="text-style" if="{{showValue}}">hello parent component!</text>
<childComp id = "selfDefineChild"></childComp>
</div>
```
```
```js
// parent.js
export default {
data: {
show: false,
showValue: false,
text: 'I am the parent component!',
},
parentClicked () {
this.show = !this.show;
this.showValue = !this.showValue
console.info('parent component get parent text');
console.info(`${this.$parent().text}`);
console.info("The parent component gets the child function.");
......@@ -286,8 +278,7 @@ export default {
Customize the child component.
```
```html
<!-- child.hml -->
<div class="item" onclick="textClicked">
<text class="text-style" onclick="childClicked">Child component clicked</text>
......@@ -295,8 +286,7 @@ Customize the child component.
</div>
```
```
```js
// child.js
export default {
data: {
......
# Defining Animations for SVG Components
You can use child components in the &lt;svg&gt; component to animate attributes over time.
You can use child components in the **\<svg>** component to animate attributes over time.
#### Attribute Style Animation
## Attribute Style Animation
In the [animate](../reference/arkui-js/js-components-svg-animate.md) child component of the &lt;svg> component, set attributeName to the attribute you want to animate, set from to the animation start value, and set to to the animation end value.
In the [animate](../reference/arkui-js/js-components-svg-animate.md) child component of the **\<svg>** component, set **attributeName** to the attribute you want to animate, set **from** to the animation start value, and set **to** to the animation end value.
```
```html
<!-- xxx.hml -->
<div class="container">
<svg>
......@@ -32,16 +33,18 @@ In the [animate](../reference/arkui-js/js-components-svg-animate.md) child compo
</div>
```
![en-us_image_0000001183871404.gif](figures/en-us_image_0000001183871404.gif)
![en-us_image_0000001183871404](figures/en-us_image_0000001183871404.gif)
> ![icon-note.gif](public_sys-resources/icon-note.gif) NOTE:
> When values is also set, the from and to settings do not take effect.
> **NOTE**
>
> When values is also set, the **from** and **to** settings do not take effect.
#### Motion Path Animation
## Motion Path Animation
In the [animateMotion](../reference/arkui-js/js-components-svg-animatemotion.md) child component of the &lt;svg&gt; component, set path to define a shape for the animation.
In the [animateMotion](../reference/arkui-js/js-components-svg-animatemotion.md) child component of the **\<svg>** component, set path to define a shape for the animation.
```
```html
<!-- xxx.hml -->
<div class="container">
<svg fill="white" width="800" height="900">
......@@ -55,13 +58,14 @@ In the [animateMotion](../reference/arkui-js/js-components-svg-animatemotion.md)
</div>
```
![en-us_image_0000001229510983.gif](figures/en-us_image_0000001229510983.gif)
![en-us_image_0000001229510983](figures/en-us_image_0000001229510983.gif)
#### animateTransform Animation
## animateTransform Animation
In the [animateTransform](../reference/arkui-js/js-components-svg-animatetransform.md) child component of the &lt;svg&gt; component, set attributeName to bind the corresponding attribute to the transform attribute, and set type to the animation type, from to the start value, and to to the end value.
```
```html
<!-- xxx.hml -->
<div class="container" style="">
<svg>
......@@ -86,7 +90,8 @@ In the [animateTransform](../reference/arkui-js/js-components-svg-animatetransfo
</div>
```
```
```css
/* xxx.css */
.container {
flex-direction: column;
......@@ -97,4 +102,4 @@ In the [animateTransform](../reference/arkui-js/js-components-svg-animatetransfo
}
```
![en-us_image_0000001182832088.gif](figures/en-us_image_0000001182832088.gif)
\ No newline at end of file
![en-us_image_0000001182832088](figures/en-us_image_0000001182832088.gif)
\ No newline at end of file
......@@ -6,10 +6,9 @@ Set the transform attribute for component rotation, scaling, translation, and sk
## Designing Static Animation
Create a square and rotate it by 90 degrees to form a rhombus. Cover the lower part of the rhombus with a rectangle to form a roof. Set the translate attribute of the rectangle to the coordinate (150px, -150px) to form a door, use the position attribute to translate the horizontal and vertical axes to the specified coordinates of the parent component (square), set the scale attribute to scale up the parent and child components together to determine the window size, and use the skewX attribute to skew the component and set the coordinate translate(200px,-830px) to form a chimney.
Create a square and rotate it by 90 degrees to form a rhombus. Cover the lower part of the rhombus with a rectangle to form a roof. Set the **translate** attribute of the rectangle to the coordinate (150px, -150px) to form a door, use the **position** attribute to translate the horizontal and vertical axes to the specified coordinates of the parent component (square), set the **scale** attribute to scale up the parent and child components together to determine the window size, and use the **skewX** attribute to skew the component and set the coordinate translate(200px,-830px) to form a chimney.
```
```html
<!-- xxx.hml -->
<div class="container">
<div class="top"></div>
......@@ -24,8 +23,7 @@ Create a square and rotate it by 90 degrees to form a rhombus. Cover the lower p
</div>
```
```
```css
/* xxx.css */
.container {
width:100%;
......@@ -41,8 +39,8 @@ Create a square and rotate it by 90 degrees to form a rhombus. Cover the lower p
height: 428px;
background-color: #860303;
transform: rotate(45deg);
margin-top: 230px;
margin-left: 266px;
margin-top: 284px;
margin-left: 148px;
}
.content{
margin-top: 500px;
......@@ -55,7 +53,7 @@ Create a square and rotate it by 90 degrees to form a rhombus. Cover the lower p
width: 100px;
height: 150px;
background-color: #1033d9;
transform: translate(150px,-150px);
transform: translate(150px,-137px);
}
.window{
z-index: 1;
......@@ -88,7 +86,7 @@ Create a square and rotate it by 90 degrees to form a rhombus. Cover the lower p
height: 100px;
border-radius: 15px;
background-color: #9a7404;
transform: translate(200px,-830px) skewX(-5deg);
transform: translate(200px,-710px) skewX(-5deg);
}
```
......@@ -99,8 +97,7 @@ Create a square and rotate it by 90 degrees to form a rhombus. Cover the lower p
Decrease the y-coordinate over a time frame to make the ball bounce back. Gradually decrease the bounce height until it drops to 0. An animation where the ball falls is hereby created.
```
```html
<!-- xxx.hml -->
<div class="container">
<div class="circle"></div>
......@@ -108,8 +105,7 @@ Decrease the y-coordinate over a time frame to make the ball bounce back. Gradua
</div>
```
```
```css
/* xxx.css */
.container {
width:100%;
......@@ -178,10 +174,9 @@ Decrease the y-coordinate over a time frame to make the ball bounce back. Gradua
## Designing Rotation Animation
Set the rotation center around an element in different transform-origin positions. Of the rotate3d values, the first three values are the rotation vectors of the x-axis, y-axis, and z-axis, respectively; the fourth value is the rotation angle, which can be a negative value to indicate that the rotation is performed counterclockwise.
Set the rotation center around an element in different transform-origin positions. Of the **rotate3d** values, the first three values are the rotation vectors of the x-axis, y-axis, and z-axis, respectively; the fourth value is the rotation angle, which can be a negative value to indicate that the rotation is performed counterclockwise.
```
```html
<!-- xxx.hml -->
<div class="container">
<div class="rotate">
......@@ -200,8 +195,7 @@ Set the rotation center around an element in different transform-origin position
</div>
```
```
```css
/* xxx.css */
.container {
flex-direction: column;
......@@ -259,13 +253,13 @@ Set the rotation center around an element in different transform-origin position
.rect4{
width: 100px;
height: 100px;
animation: rotate3d1 17ms infinite;
animation: rotate3d1 1000ms infinite;
background: linear-gradient(#e6c4ec, #be15d9)
}
.rect5{
width: 100px;
height: 100px;
animation: rotate3d1 17ms infinite;
animation: rotate3d1 1000ms infinite;
margin-left: 100px;
background: linear-gradient(#e6c4ec, #be15d9)
}
......@@ -275,7 +269,7 @@ Set the rotation center around an element in different transform-origin position
height: 100px;
border-radius: 50px;
border: 1px solid #e70303;
animation: rotate3d2 17ms infinite;
animation: rotate3d2 1000ms infinite;
}
/* Eye animation */
@keyframes rotate3d1{
......@@ -308,18 +302,18 @@ Set the rotation center around an element in different transform-origin position
![en-us_image_0000001222807776](figures/en-us_image_0000001222807776.gif)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> transform-origin specifies the origin of an element's transformation. If only one value is set, the other value is 50%. If both values are set, the first value indicates the position on the x-axis, and the second value indicates the position on the y-axis.
> **NOTE**
>
> **transform-origin** specifies the origin of an element's transformation. If only one value is set, the other value is 50%. If both values are set, the first value indicates the position on the x-axis, and the second value indicates the position on the y-axis.
## Designing Scaling Animation
This example implements a ripple animation with the scale attribute. Here is the overall procedure: First, use the positioning function to determine the coordinates of the element's position. Then, create multiple components to achieve the overlapping effect. After that, set the opacity attribute to hide or display the components. To scale and hide/display a component at the same time, set both the scale and opacity attributes. Finally, set different animation durations for different components to achieve the diffusion effect.
Set the scaling values for the x-axis, y-axis, and z-axis in scale3d to implement the animation.
Set the scaling values for the x-axis, y-axis, and z-axis in **scale3d** to implement the animation.
```
```html
<!-- xxx.hml -->
<div class="container">
<div class="circle">
......@@ -334,8 +328,7 @@ Set the scaling values for the x-axis, y-axis, and z-axis in scale3d to implemen
</div>
```
```
```css
/* xxx.css */
.container {
flex-direction: column;
......@@ -423,24 +416,23 @@ text{
![en-us_image_0000001267887837](figures/en-us_image_0000001267887837.gif)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> After the transform attributes are set, the child element changes with the parent element. Value changing of other attributes (such as height and width) of the parent element will not affect the child element.
> **NOTE**
>
> After the **transform** attributes are set, the child element changes with the parent element. Value changing of other attributes (such as height and width) of the parent element will not affect the child element.
## Setting matrix
The matrix attribute defines a transformation matrix with six input parameters: scaleX, skewY, skewX, scaleY, translateX, and translateY. In the following example, matrix is set to matrix(1,0,0,1,0,200) to skew and translate the component.
```
```html
<!-- xxx.hml -->
<div class="container">
<div class="rect"> </div>
</div>
```
```
```css
/* xxx.css */
.container{
background-color:#F1F3F5;
......@@ -474,10 +466,9 @@ The matrix attribute defines a transformation matrix with six input parameters:
## Integrating transform Attributes
You can set multiple transform attributes at the same time to apply different transformations to a component. The following example applies the scale, translate, and rotate attributes simultaneously.
You can set multiple **transform** attributes at the same time to apply different transformations to a component. The following example applies the **scale**, **translate**, and **rotate** attributes simultaneously.
```
```html
<!-- xxx.hml -->
<div class="container">
<div class="rect1"></div>
......@@ -488,8 +479,7 @@ You can set multiple transform attributes at the same time to apply different tr
</div>
```
```
```css
/* xxx.css */
.container{
flex-direction:column;
......@@ -581,9 +571,10 @@ You can set multiple transform attributes at the same time to apply different tr
![en-us_image_0000001223127712](figures/en-us_image_0000001223127712.gif)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> - When multiple transform attributes are set, the later one overwrites the previous one. To apply multiple transform styles at the same time, use the shorthand notation; that is, write multiple style values in one transform, for example, transform: scale(1) rotate(0) translate(0,0).
>
> - When using the shorthand notion, note that the animation effect varies according to the sequence of the style values.
>
> - The style values in the transform attribute used when the animation starts and ends must be in one-to-one mapping. Only the styles that have value mappings are played.
\ No newline at end of file
> **NOTE**
>
> - When multiple **transform** attributes are set, the later one overwrites the previous one. To apply multiple transform styles at the same time, use the shorthand notation; that is, write multiple style values in one transform, for example, transform: scale(1) rotate(0) translate(0,0).
>
> - When using the shorthand notation, note that the animation effect varies according to the sequence of the style values.
>
> - The style values in the **transform** attribute used when the animation starts and ends must be in one-to-one mapping. Only the styles that have value mappings are played.
\ No newline at end of file
......@@ -8,7 +8,7 @@ The **&lt;tabs&gt;** component is a common UI component for navigation. It allow
Create a **&lt;tabs&gt;** component in the .hml file under **pages/index**.
```
```html
<!-- xxx.hml -->
<div class="container">
<tabs>
......@@ -16,7 +16,7 @@ Create a **&lt;tabs&gt;** component in the .hml file under **pages/index**.
<text>item1</text>
<text>item2</text>
</tab-bar>
<tab-content>
<tab-content class="tabContent">
<div class="text">
<text>content1</text>
</div>
......@@ -28,7 +28,7 @@ Create a **&lt;tabs&gt;** component in the .hml file under **pages/index**.
</div>
```
```
```css
/* xxx.css */
.container {
flex-direction: column;
......@@ -36,6 +36,10 @@ Create a **&lt;tabs&gt;** component in the .hml file under **pages/index**.
align-items: center;
background-color: #F1F3F5;
}
.tabContent{
width: 100%;
height: 100%;
}
.text{
width: 100%;
height: 100%;
......@@ -51,7 +55,7 @@ Create a **&lt;tabs&gt;** component in the .hml file under **pages/index**.
By default, the active tab of a **&lt;tabs&gt;** component is the one with the specified **index**. To show the **&lt;tabs&gt;** vertically, set the **vertical** attribute to **true**.
```
```html
<!-- index.hml -->
<div class="container" style="background-color:#F1F3F5;">
<tabs index="1" vertical="true">
......@@ -75,7 +79,7 @@ By default, the active tab of a **&lt;tabs&gt;** component is the one with the s
Set the **mode** attribute to enable the child components of the **&lt;tab-bar&gt;** to be evenly distributed. Set the **scrollable** attribute to disable scrolling of the **&lt;tab-content&gt;**.
```
```html
<!-- index.hml -->
<div class="container" style="background-color:#F1F3F5;">
<tabs style="margin-top: 30px;">
......@@ -101,8 +105,7 @@ Set the **mode** attribute to enable the child components of the **&lt;tab-bar&g
## Setting Styles
Set the background color, border, and tab-content layout of the **&lt;tabs&gt;** component.
```
```html
<!-- index.hml -->
<div class="container">
<tabs class="tabs">
......@@ -122,7 +125,7 @@ Set the background color, border, and tab-content layout of the **&lt;tabs&gt;**
</div>
```
```
```css
/* xxx.css */
.container {
flex-direction: column;
......@@ -157,7 +160,7 @@ Set the background color, border, and tab-content layout of the **&lt;tabs&gt;**
Add the **change** event for the **&lt;tabs&gt;** component to display the index of the current tab after tab switching.
```
```html
<!-- index.hml -->
<div class="container" style="background-color:#F1F3F5;">
<tabs class="tabs" onchange="tabChange">
......@@ -177,7 +180,7 @@ Add the **change** event for the **&lt;tabs&gt;** component to display the index
</div>
```
```
```js
/* index.js */
import prompt from '@system.prompt';
export default {
......@@ -203,7 +206,7 @@ In this example, you can switch between tabs and the active tab has the title te
Use the **&lt;tabs&gt;**, **&lt;tab-bar&gt;**, and **&lt;tab-content&gt;** components to implement tab switching. Then define the arrays and attributes. Add the **change** event to change the attribute values in the arrays so that the active tab has a different font color and an underline.
```
```html
<!-- index.hml -->
<div class="container">
<tabs onchange="changeTabactive">
......@@ -231,7 +234,7 @@ Use the **&lt;tabs&gt;**, **&lt;tab-bar&gt;**, and **&lt;tab-content&gt;** compo
</div>
```
```
```css
/* xxx.css */
.container{
width: 100%;
......@@ -267,7 +270,7 @@ background-color:#F1F3F5;
}
```
```
```js
/* index.js */
import prompt from '@system.prompt';
export default {
......
......@@ -9,7 +9,7 @@ Use **CanvasRenderingContext2D** to draw objects such as graphics, texts, line s
Use **moveTo** and **lineTo** to draw a line segment. Use the **closePath** method to end current path, obtaining a closed path. Set **quadraticCurveTo** (quadratic bezier curve) or **bezierCurveTo** (cubic bezier curve) to draw a graphic.
```
```html
<!-- xxx.hml -->
<div class="container">
<canvas ref="canvas1"></canvas>
......@@ -24,9 +24,11 @@ Use **moveTo** and **lineTo** to draw a line segment. Use the **closePath** meth
```
```
```css
/* xxx.css */
.container{
width: 100%;
height: 100%;
flex-direction: column;
justify-content: center;
align-items: center;
......@@ -47,7 +49,7 @@ select{
```
```
```js
// xxx.js
import prompt from '@system.prompt';
export default {
......@@ -209,7 +211,7 @@ Globally define the canvas (**el**) and brush (**ctx**), and create a rectangle
```
```html
<!-- xxx.hml -->
<div class="container">
<canvas ref="canvas1"></canvas>
......@@ -222,11 +224,11 @@ Globally define the canvas (**el**) and brush (**ctx**), and create a rectangle
</div>
```
```
```css
/* xxx.css */
.container{
width: 100%;
height: 100%;
flex-direction: column;
justify-content: center;
align-items: center;
......@@ -246,9 +248,7 @@ select{
}
```
```
```js
// xxx.js
import prompt from '@system.prompt';
export default {
......@@ -274,7 +274,7 @@ export default {
this.ctx.setLineDash([0,0]);
// Draw a stroked rectangle.
this.ctx.strokeRect(200, 150, 200, 200);
}else if(e.newValue == 'value2'){
}else if (e.newValue == 'value2'){
this.ctx.clearRect(0,0,600,500);
this.ctx.lineWidth = 30;
this.ctx.strokeStyle = '#0000ff';
......@@ -283,12 +283,12 @@ export default {
this.ctx.arc(300, 250, 150,0,6.28);
// Draw borders.
this.ctx.stroke();
}else if(e.newValue == 'value3'){
}else if (e.newValue == 'value3'){
this.ctx.clearRect(0,0,600,500);
this.ctx.lineWidth = 5;
this.ctx.setLineDash([5,5]);
this.ctx.strokeRect(200, 150, 200, 200);
}else if(e.newValue == 'value4'){
}else if (e.newValue == 'value4'){
this.ctx.clearRect(0,0,600,500);
// Draw and fill a rectangle.
this.ctx.fillStyle = '#0000ff';
......@@ -307,7 +307,7 @@ export default {
Add the **createLinearGradient** and **createRadialGradient** attributes to create a gradient container, use the **addColorStop** method to add multiple color blocks to form a gradient color, and set **fillStyle** as **gradient** to apply the gradient color to a rectangle. Then set the shadow blur level by using **shadowBlur**, the shadow color by using **shadowColor**, and the shadow offset by using **shadowOffset**.
```
```html
<!-- xxx.hml -->
<div class="container">
<canvas ref="canvas1"></canvas>
......@@ -321,7 +321,7 @@ Add the **createLinearGradient** and **createRadialGradient** attributes to crea
```
```
```css
/* xxx.css */
.container{
flex-direction: column;
......@@ -344,7 +344,7 @@ select{
```
```
```js
// xxx.js
import prompt from '@system.prompt';
export default {
......@@ -395,9 +395,9 @@ export default {
this.ctx.fillRect(100, 100, 400, 300);
}else if(e.newValue == 'value3'){
this.ctx.clearRect(0,0,600,500);
let gradient = this.ctx.createLinearGradient(100,100, 400,400);
gradient.addColorStop(0.0, 'red');
gradient.addColorStop(0.5, 'white');
let gradient = this.ctx.createLinearGradient(100,100, 400,400);
gradient.addColorStop(0.0, 'red');
gradient.addColorStop(0.5, 'white');
gradient.addColorStop(1, '#17ea35');
// Set the level of shadow blur.
this.ctx.shadowBlur = 30;
......@@ -408,12 +408,12 @@ export default {
}else if(e.newValue == 'value4'){
this.ctx.clearRect(0,0,600,500);
this.ctx.clearRect(0,0,600,500);
let gradient = this.ctx.createRadialGradient(300,250,20,300,250,200);
gradient.addColorStop(0.0, 'red');
gradient.addColorStop(0.5, 'white');
let gradient = this.ctx.createRadialGradient(300,250,20,300,250,200);
gradient.addColorStop(0.0, 'red');
gradient.addColorStop(0.5, 'white');
gradient.addColorStop(1, '#17ea35');
// Set the level of shadow blur.
this.ctx.shadowBlur = 30;
this.ctx.shadowBlur = 30;
this.ctx.shadowOffsetY = 30;
// Set the shadow color.
this.ctx.shadowColor = 'rgb(23, 1, 1)';
......@@ -432,7 +432,7 @@ export default {
Create a text and use the **fillText** method to write the text on the canvas. Use the **globalAlpha** attribute to change the baseline transparency to avoid the text being hidden by the baseline. Then set the **textAlign** and **textBaseline** attributes to determine the text position based on the baseline.
```
```html
<!-- xxx.hml -->
<div class="container">
<canvas ref="canvas1"></canvas>
......@@ -445,7 +445,7 @@ Create a text and use the **fillText** method to write the text on the canvas. U
```
```
```css
/* xxx.css */
.container{
flex-direction: column;
......@@ -468,7 +468,7 @@ select{
```
```
```js
// xxx.js
import prompt from '@system.prompt';
export default {
......@@ -557,7 +557,8 @@ export default {
![en-us_image_0000001276162745](figures/en-us_image_0000001276162745.gif)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE:**
> **NOTE**
>
> In the **ltr** layout mode, the value **start** equals **left**. In the **rtl** layout mode, the value **start** equals **right**.
......@@ -566,7 +567,7 @@ export default {
After creating an image object, use the **drawImage** attribute to draw the image and set animation styles such as scaling, translating, and rotating.
```
```html
<!-- xxx.hml -->
<div class="container">
<div class="content">
......@@ -588,7 +589,7 @@ After creating an image object, use the **drawImage** attribute to draw the imag
```
```
```css
/* xxx.css */
.container{
flex-direction: column;
......@@ -623,7 +624,7 @@ text{
```
```
```js
// xxx.js
import prompt from '@system.prompt';
export default {
......@@ -641,8 +642,7 @@ export default {
// Set the image height.
img.height=150;
// Create an image tiling container.
var pat = ctx.createPattern(img, 'repeat');
ctx.fillStyle = pat;
var pat = ctx.createPattern(img, 'repeat');ctx.fillStyle = pat;
ctx.fillRect(0, 0, 600, 300);
},
change(){
......@@ -729,7 +729,7 @@ export default {
![en-us_image_0000001232003008](figures/en-us_image_0000001232003008.gif)
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE:**
> **NOTE**
> - Unlike the **transform()** function, the **setTransform()** function resets the existing transformation matrix and creates a transformation matrix even if it uses the same parameters.
>
> - The following formulas calculate coordinates of the transformed graph. **x** and **y** represent coordinates before transformation, and **x'** and **y'** represent coordinates after transformation.
......@@ -743,7 +743,7 @@ export default {
Use the **save** method to save the brush style, and use the **restore** method to restore the saved settings. In the following example, set the brush to red. After the brush setting is saved, clear the canvas and change the brush to blue. In this moment, directly using the brush will get a blue rectangle; using the brush after the restore operation will get a red rectangle.
```
```html
<!-- xxx.hml -->
<div class="container">
<div class="content">
......@@ -758,9 +758,11 @@ Use the **save** method to save the brush style, and use the **restore** method
```
```
```css
/* xxx.css */
.container{
width: 100%;
height: 100%;
flex-direction: column;
background-color: #F1F3F5;
align-items: center;
......@@ -792,7 +794,7 @@ text{
```
```
```js
// xxx.js
import prompt from '@system.prompt';
export default {
......@@ -817,8 +819,7 @@ export default {
restore(){
this.ctx.beginPath();
// Restore the brush setting.
this.ctx.restore();
this.ctx.fillRect(200, 150, 200, 200);
this.ctx.restore(); this.ctx.fillRect(200, 150, 200, 200);
},
}
```
......
# &lt;form&gt; Development
The &lt;form&gt; component allows the content in [&lt;input&gt;](../reference/arkui-js/js-components-basic-input.md) components to be submitted and reset. For details, see [form](../reference/arkui-js/js-components-container-form.md).
The **&lt;form&gt;** component allows the content in [&lt;input&gt;](../reference/arkui-js/js-components-basic-input.md) components to be submitted and reset. For details, see [form](../reference/arkui-js/js-components-container-form.md).
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> **NOTE**
>
> This component is supported since API version 6.
......@@ -13,7 +13,7 @@ The &lt;form&gt; component allows the content in [&lt;input&gt;](../reference/ar
Create a **&lt;form&gt;** component in the .hml file under **pages/index**.
```
```html
<!-- xxx.hml -->
<div class="container">
<form style="width: 100%; height: 20%">
......@@ -22,8 +22,7 @@ Create a **&lt;form&gt;** component in the .hml file under **pages/index**.
</div>
```
```
```css
/* xxx.css */
.container {
width:100%;
......@@ -42,7 +41,7 @@ Create a **&lt;form&gt;** component in the .hml file under **pages/index**.
To implement the zoom effect after a form is clicked, add the **click-effect** attribute to the **&lt;form&gt;** component. For values of **click-effect**, see [Universal Attributes](../reference/arkui-js/js-components-common-attributes.md).
```
```html
<!-- xxx.hml -->
<div class="container">
<form id="formId" class="formClass" click-effect="spring-large">
......@@ -58,8 +57,7 @@ To implement the zoom effect after a form is clicked, add the **click-effect** a
Add the **background-color** and **border** attributes.
```
```css
/* xxx.css */
.container {
width: 100%;
......@@ -85,7 +83,7 @@ Add the **background-color** and **border** attributes.
To submit or reset a form, add the **submit** and **reset** events.
```
```html
<!-- xxx.hml -->
<div class="container">
<form onsubmit='onSubmit' onreset='onReset' class="form">
......@@ -100,12 +98,11 @@ To submit or reset a form, add the **submit** and **reset** events.
</input>
<input type="reset" value="Reset" style="width:120px;"></input>
</div>
</form>
</div>
```
```
```css
/* index.css */
.container{
width: 100%;
......@@ -125,7 +122,7 @@ To submit or reset a form, add the **submit** and **reset** events.
}
```
```
```js
/* xxx.js */
import prompt from '@system.prompt';
export default{
......@@ -152,8 +149,7 @@ Select an option and submit or reset the form data.
Create [&lt;input&gt;](../reference/arkui-js/js-components-basic-input.md) components, set their **type** attribute to **checkbox** and **radio**, and use the **onsubmit** and **onreset** events of the **&lt;form&gt;** component to submit and reset the form data.
```
```html
<!-- xxx.hml -->
<div class="container">
<form onsubmit="formSubmit" onreset="formReset">
......@@ -188,10 +184,11 @@ Create [&lt;input&gt;](../reference/arkui-js/js-components-basic-input.md) compo
</div>
```
```
```css
/* index.css */
.container {
width: 100%;
height: 100%;
flex-direction:column;
align-items:center;
background-color:#F1F3F5;
......@@ -206,8 +203,7 @@ label{
}
```
```
```js
/* xxx.js */
import prompt from '@system.prompt';
export default {
......
......@@ -68,6 +68,7 @@ Touch the **\<grid-container>** component to call the **getColumns**, **getColum
flex-direction: column;
background-color: #F1F3F5;
width: 100%;
height: 100%;
justify-content: center;
align-items: center;
}
......@@ -155,6 +156,7 @@ After adding a **\<grid-row>** child component to **\<grid-container>**, add a *
flex-direction: column;
background-color: #F1F3F5;
width: 100%;
height: 100%;
justify-content: center;
align-items: center;
}
......@@ -205,6 +207,7 @@ In this example, the content in the list is output cyclically to create a grid l
flex-direction: column;
background-color: #F1F3F5;
width: 100%;
height: 100%;
}
text{
color: #0a0aef;
......
# Path2D
**&lt;Path2D&gt;** allows you to describe a path through an existing path. This path can be drawn through the **stroke** API of **Canvas**. For details, see [Path2D](../reference/arkui-js/js-components-canvas-path2d.md).
**\<Path2D>** allows you to describe a path through an existing path. This path can be drawn through the **stroke** API of **Canvas**. For details, see [Path2D](../reference/arkui-js/js-components-canvas-path2d.md).
## Drawing Line Segments
Create a **&lt;Path2D&gt;** object and use line segments to create different shapes.
## Drawing Line Segments
Create a **\<Path2D>** object and use line segments to create different shapes.
```
```html
<!-- xxx.hml -->
<div class="container">
<canvas ref="canvas"></canvas>
</div>
```
```
```css
/* xxx.css */
.container{
flex-direction: column;
......@@ -26,6 +23,7 @@ Create a **&lt;Path2D&gt;** object and use line segments to create different sha
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
}
canvas{
width: 600px;
......@@ -35,9 +33,7 @@ canvas{
}
```
```
```js
// xxx.js
import prompt from '@system.prompt';
export default {
......@@ -73,7 +69,7 @@ export default {
path.moveTo(600, 535);
path.arc(520, 450, 85, 0, 6);
ctx.stroke(path);
},
}
}
```
......@@ -83,10 +79,10 @@ export default {
## Drawing Graphs
Use **createPath2D** to create a path object and draw only **path1** so that only **path1** is displayed on the canvas. Click the **&lt;text&gt;** component to trigger the **addPath** method. The **path2** object is passed to **path1** as a parameter. After the **stroke** operation is performed on the **path1** object, **path1** and **path2** are displayed on the canvas. Click **Change** to change the value of **setTransform** to** setTransform(2, 0.1, 0.1, 2, 0,0)**. The graph is enlarged and tilted to the left.
Use **createPath2D** to create a path object and draw only **path1** so that only **path1** is displayed on the canvas. Click the **\<text>** component to trigger the **addPath** method. The **path2** object is passed to **path1** as a parameter. After the **stroke** operation is performed on the **path1** object, **path1** and **path2** are displayed on the canvas. Click **Change** to change the value of **setTransform** to** setTransform(2, 0.1, 0.1, 2, 0,0)**. The graph is enlarged and tilted to the left.
```
```html
<!-- xxx.hml -->
<div class="container">
<canvas ref="canvas"></canvas>
......@@ -98,7 +94,7 @@ Use **createPath2D** to create a path object and draw only **path1** so that onl
```
```
```css
/* xxx.css */
.container{
flex-direction: column;
......@@ -106,6 +102,7 @@ Use **createPath2D** to create a path object and draw only **path1** so that onl
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
}
canvas{
width: 600px;
......@@ -133,61 +130,69 @@ text{
```
```
```js
// xxx.js
import prompt from '@system.prompt';
export default {
data:{
ctx: null,
path1: null,
path2: null,
path3: null,
isAdd: "addPath2",
isChange: true,
textName: 'change'
},
onShow(){
this.ctx = this.$refs.canvas.getContext('2d',{antialias:true});
this.path1 = this.ctx.createPath2D();
this.path1.moveTo(200, 200);
this.path1.lineTo(400, 200);
this.path1.lineTo(400, 400);
this.path1.lineTo(200, 400);
this.path1.closePath();
this.path2 = this.ctx.createPath2D();
this.path2.arc(300, 300, 75, 0, 6.28)
this.ctx.stroke(this.path1);
},
addPath(){
if(this.isAdd == "addPath2"){
this.ctx.clearRect(0,0,600,600)
this.ctx.beginPath();
this.path2.addPath(this.path1)
this.ctx.stroke(this.path2);
this.isAdd = "clearPath2"
}else{
this.ctx.clearRect(0,0,600,600)
this.ctx.stroke(this.path1);
this.isAdd = "addPath2"
}
},
setTransform(){
if(this.isChange){
this.ctx.clearRect(0,0,600,600)
this.path3 = this.ctx.createPath2D();
this.path3.arc(150, 150, 100, 0, 6.28)
this.path3.setTransform(2, 0.1, 0.1, 2, 0,0);
this.ctx.stroke(this.path3);
this.isChange = !this.isChange;
this.textName = "back"
}else{
this.ctx.clearRect(0,0,600,600)
this.path3.setTransform(0.5, -0.1, -0.1, 0.5, 0,0);
this.ctx.stroke(this.path3);
this.isChange = !this.isChange;
this.textName = "change"
data: {
ctx: null,
path1: null,
path2: null,
path3: null,
isAdd: "addPath2",
isChange: true,
textName: 'change'
},
onShow() {
this.ctx = this.$refs.canvas.getContext('2d', {
antialias: true
});
this.path1 = this.ctx.createPath2D();
// Square
this.path1.moveTo(200, 200);
this.path1.lineTo(400, 200);
this.path1.lineTo(400, 400);
this.path1.lineTo(200, 400);
this.path1.closePath();
this.path2 = this.ctx.createPath2D();
// Arc
this.path2.arc(300, 300, 75, 0, 6.28);
this.ctx.stroke(this.path1);
},
addPath() {
if (this.isAdd == "addPath2") {
// Clear the content in the specified area on the canvas.
this.ctx.clearRect(0, 0, 600, 600);
this.ctx.beginPath();
// Add a path to the current path.
this.path2.addPath(this.path1);
this.ctx.stroke(this.path2);
this.isAdd = "clearPath2";
} else {
this.ctx.clearRect(0, 0, 600, 600);
this.ctx.stroke(this.path1);
this.isAdd = "addPath2";
}
},
setTransform() {
if (this.isChange) {
this.ctx.clearRect(0, 0, 600, 600);
this.path3 = this.ctx.createPath2D();
this.path3.arc(150, 150, 100, 0, 6.28);
// Reset and create a new transformation matrix.
this.path3.setTransform(2, 0.1, 0.1, 2, 0, 0);
this.ctx.stroke(this.path3);
this.isChange = !this.isChange;
this.textName = "back"
} else {
this.ctx.clearRect(0, 0, 600, 600);
this.path3.setTransform(0.5, -0.1, -0.1, 0.5, 0, 0);
this.ctx.stroke(this.path3);
this.isChange = !this.isChange;
this.textName = "change";
}
}
},
}
```
......
......@@ -10,7 +10,6 @@ Create a **&lt;switch&gt;** component in the .hml file under **pages/index**.
```html
<!-- xxx.hml -->
<div class="container">
<switch></switch>
</div>
......@@ -21,8 +20,6 @@ Create a **&lt;switch&gt;** component in the .hml file under **pages/index**.
/* xxx.css */
.container {
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #F1F3F5;
}
```
......@@ -42,7 +39,7 @@ Use the **textoff** and **showtext** attributes to set the status when text is s
```
```css
```
/* xxx.css */
.container {
width: 100%;
......@@ -52,7 +49,7 @@ Use the **textoff** and **showtext** attributes to set the status when text is s
align-items: center;
background-color: #F1F3F5;
}
switch {
switch{
texton-color: #002aff;
textoff-color: silver;
text-padding: 20px;
......@@ -61,7 +58,7 @@ switch {
```
```js
```css
// xxx.js
import prompt from '@system.prompt';
export default {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册