# Transition Styles - [Transition of Shared Elements](#en-us_topic_0000001058460505_section1884520391817) - [Precautions for Shared Elements](#en-us_topic_0000001058460505_section91806261439) - [Sample Code](#en-us_topic_0000001058460505_section1568117161452) - [Card Transition](#en-us_topic_0000001058460505_section765051220203) - [Example Code](#en-us_topic_0000001058460505_section814213323271) - [Page Transition Styles](#en-us_topic_0000001058460505_section0565021620) - [Precautions for Page Transition](#en-us_topic_0000001058460505_section99079442062) ## Transition of Shared Elements **Table 1** Transition of shared elements

Name

Type

Default Value

Description

shareid

string

N/A

Used for the transition of shared elements and takes effect only when it is configured. list-item, image, text, button, label components are supported for the transition of shared elements.

**Table 2** Transition styles of shared elements

Name

Type

Default Value

Description

shared-transition-effect

string

exchange

Entry style of shared elements during the transition, which can be exchange or static.

During the transition, the style configured on the target page takes effect preferentially.

  • exchange: The source page element is moved to the position of the target page element and is zoomed in or out properly.
  • static: The position of the target page element remains unchanged. You can configure the transparency animation. Currently, only the static effect configured on the target page takes effect.

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 transparency animations. If the effect of the shared element conflicts with the custom animation, the latter is used.

shared-transition-timing-function

string

friction

During the transition, the style configured on the target page takes effect preferentially. This attribute defines the difference curve during the transition of shared elements. The friction curve is used by default if this parameter is not configured.

## Precautions for Shared Elements 1. If shared element transition style and customized page transition style are both configured, the latter is used. 2. The exchange effect of the shared element is similar to the transition shown in the following figure. **Figure 1** Default transition effect of shared elements ![](figures/default-transition-effect-of-shared-elements.png "default-transition-effect-of-shared-elements") 3. The shared element animation does not take effect for the border and background color of the element. 4. 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. 5. During the dynamic change of **shareid**, 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. 5+ ## Sample Code Page A jumps to Page B. The shared element is **image**, and the **shareid** is "shareImage". ```
Click on picture to Jump to ths details
``` ``` // xxx.js import router from '@system.router'; export default { jump() { router.push({ uri: 'detailpage', }); }, } ``` ``` /* xxx.css */ .shared-transition-style { shared-transition-effect: exchange; shared-transition-name: shared-transition; } @keyframes shared-transition { from { opacity: 0; } to { opacity: 1; } } ``` ```
``` ``` // xxx.js import router from '@system.router'; export default { jumpBack() { router.back(); }, } ``` ``` /* xxx.css */ .shared-transition-style { shared-transition-effect: exchange; shared-transition-name: shared-transition; } @keyframes shared-transition { from { opacity: 0; } to { opacity: 1; } } ``` ## Card Transition **Table 3** Card transition style

Name

Type

Default Value

Description

transition-effect

string

-

Whether a component on the current page displays the transition effect during a card transition. Available values are as follows:

  • unfold: The component will move upwards by one card height if the component locates above the card tapped by users, or move downwards by one card height if the component locates below the card.
  • none: No transition effect is displayed.
>![](public_sys-resources/icon-note.gif) **NOTE:** >Card transitions are not available when other transitions \(including shared element transitions and custom transitions\) are used. ## Example Code The **source\_page** has a title area on the top and a card list. Users can tap a card to switch to the **target\_page**. ```
MAIN TITLE
{{$item.title}}
``` ``` // xxx.js import router from '@system.router' export default { data: { list: [] }, onInit() { for(var i = 0; i < 10; i++) { var item = { uri: "pages/card_transition/target_page/index", title: "this is title" + i, id: "item_" + i } this.list.push(item); } }, jumpPage(id, uri) { var cardId = this.$element(id).ref; router.push({ uri: uri, params : { ref : cardId } }); } } ``` ``` /* xxx.css */ .container { flex-direction: column; align-items: center; background-color: #ABDAFF; } .item { height: 80px; background-color: #FAFAFA; margin-top: 2px; } .outer { width: 300px; height: 100px; align-items: flex-end; transition-effect: unfold; } ``` ```
this is detail
``` ``` /* xxx.css */ .container { flex-direction: column; align-items: center; background-color: #EBFFD7; } .div { height: 600px; flex-direction: column; align-items: center; justify-content: center; } ``` ![](figures/卡片转场.gif) ## Page Transition Styles **Table 4** Page transition styles

Name

Type

Default Value

Description

transition-enter

string

-

Related to @keyframes, which supports transform and transparent animations. For details, see Table 2.

transition-exit

string

-

Related to @keyframes, which supports transform and transparent animations. For details, see Table 2.

transition-duration

string

Follows the default page transition time of the device.

The unit can be s or ms. The default unit is ms.

transition-timing-function

string

friction

Speed curve of executing transition animation for smoother transition. For details about the parameters, see the description of the valid values of animation-timing-function in Animation Styles.

## Precautions for Page Transition 1. When you set a customized transition, set the background color of the page to an opaque color. Otherwise, the transition effect can be harsh. 2. The **transition-enter** and **transition-exit** parameters can be configured separately. The default parameters are used if they are not configured. 3. The default value is used if **transition-duration** is not configured. 4. Notes on the **transition-enter** and **transition-exit** parameters: 1. In the push scenario, enter the animation described by **transition-enter** of the **Page2.js** application in the page stack; enter the animation described by **transition-exit** of the **Page1.js** application in the second position of the page stack; ![](figures/en-us_image_0000001058830762.png) 2. In the back scenario, exit the animation described by **transition-enter** of the **Page2.js** application in the page stack and play the animation in reverse sequence; exit the animation described by **transition-exit** of the Page1.js application in the second position of the page stack and play the animation in reverse sequence. ![](figures/en-us_image_0000001058670863.png)