1# Transition Styles
2
3>  **NOTE**
4>
5>  Supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
6
7## Transition of Shared Elements
8
9
10### Attributes
11
12| Name     | Type    | Default Value | Description                                      |
13| ------- | ------ | ---- | ---------------------------------------- |
14| shareid | string | -   | Used for the transition of shared elements, which takes effect only when this attribute is set. **\<list-item>**, **\<image>**, **\<text>**, **\<button>**, and **\<label>** components are supported for the transition of shared elements.|
15
16
17### Styles
18
19| Name                               | Type    | Default Value     | Description                                      |
20| --------------------------------- | ------ | -------- | ---------------------------------------- |
21| shared-transition-effect          | string | exchange | Entry style of a shared element during transition.<br>- **exchange** (default): The source page element is moved to the position of the target page element and is zoomed in or out properly.<br>- **static**: The position of the target page element remains unchanged. You can configure the opacity animation. Currently, only the static effect configured on the target page takes effect.|
22| shared-transition-name            | string | -        | During the transition, the style configured on the target page takes effect preferentially. This style is used to configure the animation effect of shared elements. The animation effect is an animation sequence defined by **@keyframes** supporting transform and opacity animations. If the effect of shared elements conflicts with the custom animation, the latter is used.|
23| shared-transition-timing-function | string | friction | During the transition, the style configured on the target page takes effect preferentially. This style defines the difference curve during the transition of shared elements. If it is not configured, the friction curve is used.|
24
25
26### Important Notes
27
281. If the shared element transition style and custom page transition style are both configured, the latter is used.
29
302. The exchange effect of shared elements is similar to the transition shown below.
31
32**Figure 1** Default transition effect of shared elements
33![en-us_image_0000001238424309](figures/en-us_image_0000001238424309.png)
34
353. The animation of a shared element does not take effect for the border and background color of the element.
36
374. During the transition of a shared element, the page element is hidden. Therefore, the animation style and function set for the page element are invalid.
38
395. During the dynamic change of **shareid**<sup>5+</sup>, if the **shareid** value in component A is overwritten by that in component B, the shared element effect of component A becomes ineffective and will not be restored even if the **shareid** value is changed in component B.
40
41
42### Example
43
44In the example below, where **PageA** jumps to **PageB**, the shared element is **image**, and the **shareid** is "shareImage".
45
46```html
47<!-- PageA -->
48<!-- xxx.hml -->
49<div>
50  <list>
51    <list-item type="description">
52      <image src="item.jpg" shareid="shareImage" onclick="jump" class="shared-transition-style"></image>
53    </list-item>
54    <list-item>
55      <text onclick="jump">Click on picture to jump to the details</text>
56    </list-item>
57  </list>
58</div>
59```
60
61```js
62// xxx.js
63import router from '@ohos.router';
64export default {
65  jump() {
66    router.push({
67      // The path must be the same as that in the config.json file.
68      url: 'pages/detailpage',
69    });
70  },
71}
72```
73
74```css
75/* xxx.css */
76.shared-transition-style {
77  shared-transition-effect: exchange;
78  shared-transition-name: shared-transition;
79}
80@keyframes shared-transition {
81  from { opacity: 0; }
82  to { opacity: 1; }
83}
84```
85
86```html
87<!-- PageB -->
88<!-- xxx.hml -->
89<div>
90  <image src="itemDetail.jpg" shareid="shareImage" onclick="jumpBack" class="shared-transition-style"></image>
91</div>
92```
93
94```js
95// xxx.js
96import router from '@ohos.router';
97export default {
98  jumpBack() {
99    router.back();
100  },
101}
102```
103
104```css
105/* xxx.css */
106.shared-transition-style {
107  shared-transition-effect: exchange;
108  shared-transition-name: shared-transition;
109}
110@keyframes shared-transition {
111  from { opacity: 0; }
112  to { opacity: 1; }
113}
114```
115
116
117## Widget Transition
118
119>  **NOTE**
120>  Widget transitions are not available when other transitions (including shared element transitions and custom transitions) are used.
121
122
123### Styles
124
125| Name               | Type    | Default Value | Description                                      |
126| ----------------- | ------ | ---- | ---------------------------------------- |
127| transition-effect | string | -    | Whether a component on the current page displays the transition effect during a widget transition. Available values are as follows:<br>- **unfold**: The component will move upwards by one widget height if the component is located above the widget tapped by the user, or move downwards by one widget height if the component is located below the widget.<br>- **none**: No transition effect is displayed.|
128
129
130### Example
131
132The **source_page** has a title area on the top and a widget list. Users can tap a widget to switch to the **target_page**.
133
134```html
135<!-- source_page -->
136<!-- xxx.hml -->
137<div class="container">
138  <div class="outer">
139    <text style="font-size: 23px; margin-bottom: 20px" >MAIN TITLE</text>
140  </div>
141  <list style="width:340px;height:600px;flex-direction:column;justify-content:center;align-items:center">
142    <list-item type="listItem" class="item" card="true" for="list" id="{{$item.id}}" onclick="jumpPage({{$item.id}}, {{$item.url}})">
143      <text style="margin-left: 10px; font-size: 23px;">{{$item.title}}</text>
144    </list-item>
145  </list>
146</div>
147```
148
149```js
150// xxx.js
151import router from '@ohos.router'
152export default {
153  data: { list: [] },
154  onInit() {
155    for(var i = 0; i < 10; i++) {
156      var item = { url: "pages/card_transition/target_page/index",
157                   title: "this is title" + i, id: "item_" + i }
158      this.list.push(item);
159    }
160  },
161  jumpPage(id, url) {
162    var cardId = this.$element(id).ref;
163    router.push({ url: url, params : { ref : cardId } });
164  }
165}
166```
167
168```css
169/* xxx.css */
170.container {
171  width: 100%;
172  height: 100%;
173  flex-direction: column;
174  align-items: center;
175  background-color: #ABDAFF;
176}
177.item {
178  height: 80px;
179  background-color: #FAFAFA;
180  margin-top: 2px;
181}
182.outer {
183  width: 300px;
184  height: 100px;
185  align-items: flex-end;
186  transition-effect: unfold;
187}
188```
189
190```html
191<!-- target_page -->
192<!-- xxx.hml -->
193<div class="container">
194  <div class="div">
195    <text style="font-size: 30px">this is detail</text>
196  </div>
197</div>
198```
199
200```css
201/* xxx.css */
202.container {
203  width: 100%;
204  height: 100%;
205  flex-direction: column;
206  align-items: center;
207  background-color: #EBFFD7;
208}
209.div {
210  height: 600px;
211  flex-direction: column;
212  align-items: center;
213  justify-content: center;
214}
215```
216
217![en-us_image_0000001193544358](figures/en-us_image_0000001193544358.gif)
218
219
220## Page Transition
221
222
223### Styles
224
225| Name                        | Type    | Default Value          | Description                                      |
226| -------------------------- | ------ | ------------- | ---------------------------------------- |
227| transition-enter           | string | -             | Works with **@keyframes** and supports transform and opacity animations. For details, see [Attributes available for the @keyframes rule](js-components-common-animation.md).|
228| transition-exit            | string | -             | Works with **@keyframes** and supports transform and opacity animations. For details, see [Attributes available for the @keyframes rule](js-components-common-animation.md).|
229| transition-duration        | string | Follows the default page transition time of the device| The unit can be s|or ms. The default unit is ms. If no value is specified, the default value is used.|
230| transition-timing-function | string | friction      | Speed curve of the transition animation, which makes the animation more fluent. For details, see the description of **animation-timing-function **in [Animation Styles](js-components-common-animation.md).|
231
232
233### Important Notes
234
2351. When defining a custom transition, set the page background color to an opaque color. Otherwise, the transition effect can be harsh.
236
2372. The **transition-enter** and **transition-exit** styles can be configured separately. The default settings are used if they are not configured.
238
2393. Notes on the **transition-enter** and **transition-exit** styles:
240
241   a. In the push scenario, the animation defined by **transition-enter** is used for entering the **Page2.js** in the page stack; the animation defined by **transition-exit** is used for entering the **Page1.js** in the page stack.
242   ![en-us_image_0000001193704354](figures/en-us_image_0000001193704354.png)
243
244   b. In the back scenario, the animation defined by **transition-enter** is used for exiting the **Page2.js** in the page stack, with the animation played in reverse sequence; the animation defined by **transition-exit** is used for exiting the **Page1.js** in the page stack, with the animation played in reverse sequence.
245   ![en-us_image_0000001238184345](figures/en-us_image_0000001238184345.png)
246
247### Example
248
249**Page1** has an opaque box. When you tap the box, **Page2** is displayed. When you tap the box on **Page2**, **Page1** is displayed.
250
2511. Page1
252
253   ```html
254   <!-- xxx.hml -->
255   <div class="container">
256       <text>index</text>
257       <div class="move_page" onclick="jump"></div>
258   </div>
259   ```
260
261   ```js
262   // xxx.js
263   import router from '@ohos.router';
264   export default {
265       data: {
266
267       },
268       jump() {
269           router.push({
270               url:'pages/transition2/transition2'
271           })
272       }
273   }
274   ```
275
276   ```css
277   /* xxx.css */
278   .container {
279       flex-direction: column;
280       justify-content: center;
281       align-items: center;
282       width: 100%;
283       height: 100%;
284   }
285   .move_page {
286       width: 100px;
287       height: 100px;
288       background-color: #72d3fa;
289       transition-enter: go_page;
290       transition-exit: exit_page;
291       transition-duration: 5s;
292       transition-timing-function: friction;
293   }
294
295   @keyframes go_page {
296       from {
297           opacity: 0;
298           transform: translate(0px) rotate(60deg) scale(1.0);
299       }
300
301       to {
302           opacity: 1;
303           transform: translate(100px) rotate(360deg) scale(1.0);
304       }
305   }
306   @keyframes exit_page {
307       from {
308           opacity: 1;
309           transform: translate(200px) rotate(60deg) scale(2);
310       }
311
312       to {
313           opacity: 0;
314           transform: translate(200px) rotate(360deg) scale(2);
315       }
316   }
317   ```
318
319
3202. Page2
321
322   ```html
323   <!-- xxx.hml -->
324   <div class="container">
325       <text>transition</text>
326       <div class="move_page" onclick="jumpBack"></div>
327   </div>
328   ```
329
330   ```js
331   // xxx.js
332   import router from '@ohos.router';
333   export default {
334       data: {
335
336       },
337       jumpBack() {
338           router.back()
339       }
340   }
341   ```
342
343   ```css
344   /* xxx.css */
345   .container {
346       flex-direction: column;
347       justify-content: center;
348       align-items: center;
349       width: 100%;
350       height: 100%;
351   }
352
353   .move_page {
354       width: 100px;
355       height: 100px;
356       background-color: #f172fa;
357       transition-enter: go_page;
358       transition-exit: exit_page;
359       transition-duration: 5s;
360       transition-timing-function: ease;
361   }
362
363   @keyframes go_page {
364       from {
365           opacity: 0;
366           transform:translate(100px) rotate(0deg) scale(1.0);
367       }
368       to {
369           opacity: 1;
370           transform:translate(100px) rotate(180deg) scale(2.0);
371       }
372   }
373
374   @keyframes exit_page {
375       from {
376           opacity: 1;
377           transform: translate(0px) rotate(60deg) scale(1);
378       }
379       to {
380           opacity: 0;
381           transform: translate(0px) rotate(360deg) scale(1);
382       }
383   }
384   ```
385
386   ![transition](figures/transition.gif)
387