https://pastebin.com/ZjxPmYcs
我期望类似的行为,只有一个大块并且没有平滑滚动 - https://stackblitz.com/edit/react-iqmjfx?file=src%2FApp.js
首先,运行以下命令来安装必要的软件包
npm i gsap-trial @gsap/react
之后,尝试下面的代码
import { useRef } from "react";
import gsap from "gsap-trial";
import { ScrollTrigger } from "gsap-trial/ScrollTrigger";
import { useGSAP } from "@gsap/react";
import "./App.css";
gsap.registerPlugin(useGSAP, ScrollTrigger);
function App() {
const container = useRef<any>(null);
useGSAP(
() => {
ScrollTrigger.create({
trigger: ".box-c",
pin: true,
start: "center center",
end: '+=' + (container.current?.clientHeight - 400),
markers: false,
});
},
{ scope: container }
);
return (
<div
ref={container}
style={{ width: "100%", overflow: "visible", height: "200vh" }}
>
<div
className="box-c"
style={{
position: "absolute",
left: "50%",
transform: "translateX(-50%)",
zIndex: 100,
backgroundColor: "green",
width: 50,
height: 50,
top: "0px",
}}
>
s
</div>
</div>
);
}
export default App;