# share-element

> 基础库 2.16.0 开始支持，低版本需做[兼容处理](/miniprogram/dev/framework/compatibility.md)。

> __微信 Windows 版__：支持
>
> __微信 Mac 版__：支持
>
> __微信 鸿蒙 OS 版__：支持

渲染框架支持情况：Skyline （使用最新 [Nightly](/miniprogram/dev/devtools/nightly.html) 工具调试）、WebView

## 功能描述

共享元素。

共享元素是一种动画形式，类似于 [flutter Hero](https://flutterchina.club/animations/hero-animations/)动画，表现为元素像是在页面间穿越一样。该组件需与 [page-container](/miniprogram/dev/component/page-container) 组件结合使用。

使用时需在当前页放置 `share-element` 组件，同时在 `page-container` 容器中放置对应的 `share-element` 组件，对应关系通过属性值 `key` 映射。当设置 `page-container` 显示时，`transform` 属性为 `true` 的共享元素会产生动画。当前页面容器退出时，会产生返回动画。

1. 使用 `worklet` 函数需要开启开发者工具 "将 JS 编译成 ES5" 或 "编译 worklet 函数" 选项。

## 通用属性


```json
[
  {
    "属性": "key",
    "类型": "string",
    "默认值": "",
    "必填": "是",
    "说明": "映射标记，页面内唯一",
    "最低版本": "[2.29.2](/miniprogram/dev/framework/compatibility.md)"
  },
  {
    "属性": "transform",
    "类型": "boolean",
    "默认值": "false",
    "必填": "否",
    "说明": "是否进行动画",
    "最低版本": "[2.16.0](/miniprogram/dev/framework/compatibility.md)"
  },
  {
    "属性": "duration",
    "类型": "number",
    "默认值": "300",
    "必填": "否",
    "说明": "动画时长，单位毫秒",
    "最低版本": "[2.16.0](/miniprogram/dev/framework/compatibility.md)"
  },
  {
    "属性": "easing-function",
    "类型": "string",
    "默认值": "ease-out",
    "必填": "否",
    "说明": "\u0000INLINECODE_8\u0000缓动函数",
    "最低版本": "[2.16.0](/miniprogram/dev/framework/compatibility.md)"
  }
]
```

## Skyline 特有属性


```json
[
  {
    "属性": "transition-on-gesture",
    "类型": "boolean",
    "默认值": "false",
    "必填": "否",
    "说明": "手势返回时是否进行动画",
    "最低版本": "[2.29.2](/miniprogram/dev/framework/compatibility.md)"
  },
  {
    "属性": "shuttle-on-push",
    "类型": "string",
    "默认值": "to",
    "必填": "否",
    "说明": "指定 push 阶段的飞跃物",
    "最低版本": "[2.30.2](/miniprogram/dev/framework/compatibility.md)",
    "子项": [
      {
        "合法值": "from",
        "说明": "push 阶段采用源页面节点作为飞跃物"
      },
      {
        "合法值": "to",
        "说明": "push 阶段采用目标页面节点作为飞跃物"
      },
      {
        "合法值": "from",
        "说明": "pop 阶段采用源页面节点作为飞跃物"
      },
      {
        "合法值": "to",
        "说明": "pop 阶段采用目标页面节点作为飞跃物"
      }
    ]
  },
  {
    "属性": "shuttle-on-pop",
    "类型": "string",
    "默认值": "to",
    "必填": "否",
    "说明": "指定 pop 阶段的飞跃物",
    "最低版本": "[2.30.2](/miniprogram/dev/framework/compatibility.md)"
  },
  {
    "属性": "worklet:onframe",
    "类型": "callback",
    "默认值": "",
    "必填": "否",
    "说明": "动画帧回调",
    "最低版本": "[2.30.2](/miniprogram/dev/framework/compatibility.md)"
  },
  {
    "属性": "rect-tween-type",
    "类型": "string",
    "默认值": "materialRectArc",
    "必填": "否",
    "说明": "动画插值曲线",
    "最低版本": "[2.30.2](/miniprogram/dev/framework/compatibility.md)",
    "子项": [
      {
        "合法值": "materialRectArc",
        "说明": "矩形对角动画"
      },
      {
        "合法值": "materialRectCenterArc",
        "说明": "径向动画"
      },
      {
        "合法值": "linear",
        "说明": ""
      },
      {
        "合法值": "elasticIn",
        "说明": ""
      },
      {
        "合法值": "elasticOut",
        "说明": ""
      },
      {
        "合法值": "elasticInOut",
        "说明": ""
      },
      {
        "合法值": "bounceIn",
        "说明": ""
      },
      {
        "合法值": "bounceOut",
        "说明": ""
      },
      {
        "合法值": "bounceInOut",
        "说明": ""
      },
      {
        "合法值": "cubic-bezier(x1, y1, x2, y2",
        "说明": ")"
      }
    ]
  }
]
```

## WebView 示例代码

[在开发者工具中预览效果](https://developers.weixin.qq.com/s/NqVP7ImA73ou)

## Skyline 示例代码

[在开发者工具中预览效果](https://developers.weixin.qq.com/s/t584gymu7VMM)
