带时间线的 Gsap 滚动触发器
我正在使用 gsap 制作 React 应用程序。我在时间轴中使用滚动触发器,但它不起作用。滚动触发器无法工作。有人可以帮助我吗?这是我的代码
gsap.registerPlugin(ScrollTrigger);
const el = useRef(null);
const q = gsap.utils.selector(el);
useEffect(() => {
让 tl = gsap.timeline({ 滚动触发器:{
触发:q(".scrollDist"),
开始:“顶顶”,
结束:“底部中心”,
擦洗:1,
标记:true,
<代码>}, });
tl.fromTo(
q(".header"),
{ y: 0, opacity: 1 },
{ y: -100, opacity: 0 }
).fromTo(".button_field", { y: 0 }, { y: -50 });
}, []);
I'm making react app using gsap. I use scrolltrigger in timeline but it's not working. The scrolltrigger couldn't work.Can someone help me? Here is my code
gsap.registerPlugin(ScrollTrigger);
const el = useRef(null);
const q = gsap.utils.selector(el);
useEffect(() => {
let tl = gsap.timeline({
scrollTrigger: {
trigger: q(".scrollDist"),
start: "top top",
end: " bottom center",
scrub: 1,
markers: true,
},
});
tl.fromTo(
q(".header"),
{ y: 0, opacity: 1 },
{ y: -100, opacity: 0 }
).fromTo(".button_field", { y: 0 }, { y: -50 });
}, []);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有正确的代码片段,有点难以理解您想要实现的目标,但我会破解的。
乍一看,您似乎需要将
scrub: 1
配置更改为scrub: true
。另一个问题是它可能无法正确查询元素,如果不看到标记就很难判断。
这是对 React 组件中完整代码的假设。
A tad hard to pick up on what you're trying to achieve without a proper code snippet but I'll have a crack.
First glance it looks like you need to change the
scrub: 1
config toscrub: true
.The other concern is it may not be querying for the elements properly, hard to tell without seeing the markup.
This is an assumption of the full code you have within your React component.
我正在使用此代码片段构建时间线
并使用 const tl = myTimeline.current;
I am using this snippet to build a timeline
And use
const tl = myTimeline.current;