如何在React中使用gsap.from()

发布于 2025-01-23 12:43:38 字数 166 浏览 0 评论 0原文

我正在尝试创建一个交错动画,其中三个点出现,延迟为0.2s 这是我为第一个点编写的代码,它应该从不透明度转到不透明度:1(作为圆圈的默认不透明度为1),但是不透明度保留0,从未更改为1

GSAP. ,{ 持续时间:0.2, 不透明度:0, X:20, 轻松:“ Power.4.easein”, });

I am trying to create a stagger animation where three dots appear with a delay of 0.2s
This is the code I wrote for the first dot, it is supposed to go from opacity:0 to opacity: 1 (as the default opacity of the circle is 1) but the opacity remains 0 and never changed to 1

gsap.from(circle, {
duration: 0.2,
opacity: 0,
x: 20,
ease: "Power4.easeInOut",
});

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

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

发布评论

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

评论(1

dawn曙光 2025-01-30 12:43:38

我认为这会解决

import { useLayoutEffect } from "react";
import "./App.css";
import gsap from "gsap";

function App() {
  useLayoutEffect(() => {
    let from = gsap.from(".circle", {
      duration: 1.5,
      opacity: 0,
      stagger: 0.2,
      immediateRender: false,
    });
    return () => {
      from.kill();
    };
  });

  return (
    <div className="App">
      <div className="_con">
        <div className="circle"></div>
        <div className="circle"></div>
        <div className="circle"></div>
      </div>
    </div>
  );
}

export default App;

I think it will fix

import { useLayoutEffect } from "react";
import "./App.css";
import gsap from "gsap";

function App() {
  useLayoutEffect(() => {
    let from = gsap.from(".circle", {
      duration: 1.5,
      opacity: 0,
      stagger: 0.2,
      immediateRender: false,
    });
    return () => {
      from.kill();
    };
  });

  return (
    <div className="App">
      <div className="_con">
        <div className="circle"></div>
        <div className="circle"></div>
        <div className="circle"></div>
      </div>
    </div>
  );
}

export default App;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文