1# Motion Blur
2
3You can apply a motion blur effect to a component being scaled or moved. This effect must be used together with the **onFinish** parameter of **AnimateParam**.
4
5>  **NOTE**
6>
7>  The initial APIs of this module are supported since API version 12. Updates will be marked with a superscript to indicate their earliest API version.
8
9
10## motionBlur
11
12motionBlur(value: MotionBlurOptions)
13
14Apply a motion blur effect to the component being scaled or moved.
15
161. Do not use this API in intra-component transitions, shared element transitions, implicit element transitions, or particle animations. Doing so may cause unexpected results.
17
182. The **radius** parameter of **motionBlur** must be set to **0** for the initial state. Otherwise, there may be unexpected results during a cold start.
19
203. This API must be used together with the **onFinish** parameter of **AnimateParam**. Its **radius** parameter must be set to **0** when the animation ends; otherwise, there may be unexpected results.
21
224. When using this API, do not frequently change the blur radius of the same component; otherwise, there may be unexpected results. For example, if you frequently click the image in the example, the blur effect may not work sometimes.
23
245. To avoid unexpected results, make sure the coordinates of the motion blur anchor point are the same as those of the animation scaling anchor point.
25
266. To avoid unexpected results, set the blur radius to a value less than 1.
27
28**Parameters**
29
30| Name | Type                                                        | Mandatory| Description                                                        |
31| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
32| value   | [MotionBlurOptions](#motionbluroptions) | Yes  | Motion blur options.|
33
34## MotionBlurOptions
35
36| Name         | Type                                                       | Mandatory | Description                                                        |
37| ------------- | ----------------------------------------------------------- | ----- | ------------------------------------------------------------ |
38| radius | number      | Yes   | Blur radius. The value range is [0.0, ∞). You are advised to set it to a value less than 1.0.|
39| anchor | [MotionBlurAnchor](#motionbluranchor) | Yes   | Coordinates of the motion blur anchor point. They must be the same as those of the animation scaling anchor point.|
40
41## MotionBlurAnchor
42
43| Name         | Type                                                       | Mandatory | Description                                                        |
44| ------------- | ----------------------------------------------------------- | ----- | ------------------------------------------------------------ |
45| x | number      | Yes   | X-coordinate of the anchor point. The value range is [0.0, 1.0].|
46| y | number      | Yes   | Y-coordinate of the anchor point. The value range is [0.0, 1.0].|
47
48## Example
49
50This example demonstrates how to apply a motion blur effect.
51```ts
52// xxx.ets
53import curves from '@ohos.curves';
54
55@Entry
56@Component
57struct motionBlurTest {
58  @State widthSize: number = 400
59  @State heightSize: number = 320
60  @State flag: boolean = true
61  @State radius: number = 0
62  @State x: number = 0
63  @State y: number = 0
64
65  build() {
66    Column() {
67      Column() {
68        Image($r('app.media.testImg'))
69          .width(this.widthSize)
70          .height(this.heightSize)
71          .onClick(() => {
72            this.radius = 5;
73            this.x = 0.5;
74            this.y = 0.5;
75            if (this.flag) {
76              this.widthSize = 100;
77              this.heightSize = 80;
78            } else {
79              this.widthSize = 400;
80              this.heightSize = 320;
81            }
82            this.flag = !this.flag;
83          })
84          .animation({
85            duration: 2000,
86            curve: curves.springCurve(10, 1, 228, 30),
87            onFinish: () => {
88              this.radius = 0;
89            }
90          })
91          .motionBlur({ radius: this.radius, anchor: { x: this.x, y: this.y } })
92      }
93    }.width('100%').margin({ top: 5 })
94  }
95}
96```
97
98![motionBlurTest](figures/motionBlur.gif)
99