Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

动画显示不完全 #21

Open
Jethro-Cheng opened this issue Oct 14, 2022 · 0 comments
Open

动画显示不完全 #21

Jethro-Cheng opened this issue Oct 14, 2022 · 0 comments

Comments

@Jethro-Cheng
Copy link

Jethro-Cheng commented Oct 14, 2022

react 18.2 只有enter到leave的动画 没有from到enter的动画 新手望指点

import { Button } from "antd";
import { useSwitchTransition } from "transition-hook";


export default function Test() {
  const [count, setCount] = useState(0);
  const transition = useSwitchTransition(count, 300, "default");

  return (
    <div className="BasicSwitchTransition">
      <div
        style={{
          display: "flex",
          justifyContent: "center",
          alignItems: "center",
          gap: 40,
          marginTop: 50,
        }}
      >
        <Button onClick={() => setCount(count - 1)}>-1</Button>
        <div
          style={{
            width: 150,
            display: "grid",
            placeItems: "center",
            perspective: 200,
          }}
        >
          {transition((state, stage) => (
            <h1
              style={{
                fontSize: "5em",
                position: "absolute",
                transition: ".3s",
                opacity: stage === "enter" ? 1 : 0,
                transform: {
                  from: "translateY(-100%) rotateX(60deg) scale(.5)",
                  enter: "translateY(0%)",
                  leave: "translateY(100%) rotateX(-60deg) scale(.5)",
                }[stage],
              }}
            >
              {state}
            </h1>
          ))}
        </div>
        <Button onClick={() => setCount(count + 1)}>+1</Button>
      </div>

      <div
        style={{
          display: "flex",
          justifyContent: "center",
          alignItems: "center",
          flexDirection: "column",
          gap: 40,
          marginTop: 100,
        }}
      >
        <Button onClick={() => setCount(count - 1)}>-1</Button>
        <div
          style={{
            width: 150,
            display: "grid",
            placeItems: "center",
            perspective: 200,
          }}
        >
          {transition((state, stage) => (
            <h1
              style={{
                fontSize: "2em",
                position: "absolute",
                transition: ".3s",
                opacity: stage === "enter" ? 1 : 0,
                transform: {
                  from: "translateX(-100%) rotateY(-60deg) scale(.5)",
                  enter: "translateX(0%)",
                  leave: "translateX(100%) rotateY(60deg) scale(.5)",
                }[stage],
              }}
            >
              {state}
            </h1>
          ))}
        </div>
        <Button onClick={() => setCount(count + 1)}>+1</Button>
      </div>
    </div>
  );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant