如何使用AnimationMotion>在反应中?

发布于 2025-01-29 07:20:17 字数 272 浏览 1 评论 0 原文

当动画结束时,我想删除DOM,但是我还没有在React Docs https://zh-hans.reactjs.org/docs/events.html#animation-events中找到Onend事件。

这是demo

I want to remove the dom when then animation ended of , but I haven't found the onend event in react docs https://zh-hans.reactjs.org/docs/events.html#animation-events.

Here is the demo https://codesandbox.io/s/ecstatic-cherry-7nyh7r?file=/src/App.js

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小镇女孩 2025-02-05 07:20:17

我找到了Mayself的道路!

// jsx part
<animateMotion ref={handleMotionRef}></animateMotion>

// js part
  function handleMotionRef(node) {
    // node?.onend = () => {} or
    node?.addEventListener(
      'beginEvent',
      (e) => {
        e.target.parentNode.style.display = 'block';
      },
      false,
    );
    node?.addEventListener(
      'endEvent',
      (e) => {
        e.target.parentNode.style.display = 'none';
      },
      false,
    );
  }

I found the way by mayself!

// jsx part
<animateMotion ref={handleMotionRef}></animateMotion>

// js part
  function handleMotionRef(node) {
    // node?.onend = () => {} or
    node?.addEventListener(
      'beginEvent',
      (e) => {
        e.target.parentNode.style.display = 'block';
      },
      false,
    );
    node?.addEventListener(
      'endEvent',
      (e) => {
        e.target.parentNode.style.display = 'none';
      },
      false,
    );
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文