Skip to Content
文档

存在

用于在控制渲染行为的同时,为元素的进入和退出添加动画效果。

SourceStorybookRecipeArk

用法

¥Usage

import { Presence } from "@chakra-ui/react"
<Presence present={true}>
  <div>Presence content</div>
</Presence>

可以将 Presence 视为 Framer Motion 中的 AnimatePresence 组件,只不过它是为 CSS 动画构建的。

¥Think of Presence like the AnimatePresence component from Framer Motion, except that it's built for CSS animations instead.

需要注意的关键事项:

¥The key things to note:

  • present prop 是一个布尔值,用于控制组件的存在状态。

  • _open 条件用于设置打开状态的样式。

  • _closed 条件用于设置关闭状态的样式。

示例

¥Examples

淡入淡出

¥Fade

将动画名称设置为 fade-infade-out,组件将为元素的进入和退出添加动画。

¥Setting the animation name to fade-in and fade-out, the component will animate the entry and exit of the element.

缩放淡入淡出

¥Scale Fade

使用动画样式 scale-fade-inscale-fade-out,组件将为元素的进入和退出添加动画。

¥Using the animation styles scale-fade-in and scale-fade-out, the component will animate the entry and exit of the element.

滑动淡入淡出

¥Slide Fade

以下是使用动画名称 slide-from-bottomslide-to-bottom 为元素的进入和退出设置动画的示例。

¥Here's an example that uses the animation names slide-from-bottom and slide-to-bottom to animate the entry and exit of the element.

滑动

¥Slide

以下是使用动画名称 slide-from-bottom-fullslide-to-bottom-full 为元素的进入和退出设置动画的示例。

¥Here's an example that uses the animation names slide-from-bottom-full and slide-to-bottom-full to animate the entry and exit of the element.

延迟加载

¥Lazy Mount

使用 lazyMount 属性延迟组件的挂载,直到其出现。

¥Use the lazyMount prop to delay the mount of the component until it's present.

Check the DOM to see that the element not mounted initially

退出时卸载

¥Unmount On Exit

使用 unmountOnExit 属性在组件不存在时卸载组件。

¥Use the unmountOnExit prop to unmount the component when it's not present.

Check the DOM to see that the element is removed when not present.

Previous

用于

Next

门户