当我使用机车滚动和滚动扳机时,获得一些粘性动画
这是我第一次在 gsap 中尝试滚动触发器,我试图了解机车滚动和滚动触发器如何协同工作,但是当动画进行时,我在动画中面临某种粘性,我的意思是动画在那里不平滑两者之间存在某种延迟,但我不知道其原因是什么。我尝试在我的代码笔中重现这种情况,我在下面链接了它。如果有人可以帮助我解决这个问题,那将会很有帮助这是我重新创建错误的代码笔代码。 code-pen
这是代码
gsap.registerPlugin(ScrollTrigger);
const pageContainer = document.querySelector(".scrollContainer");
const scroller = new LocomotiveScroll({
el: pageContainer,
smooth: true,
});
scroller.on("scroll", ScrollTrigger.update);
ScrollTrigger.scrollerProxy(pageContainer, {
scrollTop(value) {
return arguments.length
? scroller.scrollTo(value, 0, 0)
: scroller.scroll.instance.scroll.y;
},
getBoundingClientRect() {
return {
top: 0,
left: 0,
width: window.innerWidth,
height: window.innerHeight,
};
},
pinType: document.querySelector(".scrollContainer").style.transform
? "transform"
: "fixed",
});
// ! edit here
gsap.to(".left", {
scrollTrigger: {
trigger: ".left",
start: "center top",
scroller: pageContainer,
scrub: true,
},
duration: 1,
x:50
});
ScrollTrigger.addEventListener("refresh", () => scroller.update());
ScrollTrigger.refresh();
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root{
--white:#fff;
}
body{
font-family: 'neue-med';
background-color: #D4C9C9;
}
.container{
padding: 35px;
height: 200vh
}
h4{
letter-spacing: 1px;
display: inline-block;
font-size: 25px;
transition: .2s ease-in;
}
h4:hover{
color: whitesmoke;
cursor: pointer;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/locomotive-scroll.css"
/>
<!-- <link rel="stylesheet" href="/base.css"> -->
<link rel="stylesheet" href="/style.css" />
<title>Document</title>
</head>
<body>
<div class="container scrollContainer">
<div class="sec" data-scroll-section>
<div class="nav">
<div class="nav-text">
<h4 class="left">LOCOMOTIVE.CA</h4>
<h4 class="right" style="float: right">V4.X-EDITION</h4>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.3/gsap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.3/ScrollTrigger.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/locomotive-scroll.min.js"></script>
</body>
</html>
This is my first time trying scroll trigger in gsap I am trying to understand how locomotive scroll and scroll trigger work together but when the animation is going on I am facing some kind of sticky-ness in the animation I mean the animation is not smooth there is some kind of delay in between but I don't know what is the reason for this. I tried to recreate this situation in my code pen which I have linked below. It will be helpful if someone can help me to solve this Here is my code-pen code where I recreated the error. code-pen
here is the code
gsap.registerPlugin(ScrollTrigger);
const pageContainer = document.querySelector(".scrollContainer");
const scroller = new LocomotiveScroll({
el: pageContainer,
smooth: true,
});
scroller.on("scroll", ScrollTrigger.update);
ScrollTrigger.scrollerProxy(pageContainer, {
scrollTop(value) {
return arguments.length
? scroller.scrollTo(value, 0, 0)
: scroller.scroll.instance.scroll.y;
},
getBoundingClientRect() {
return {
top: 0,
left: 0,
width: window.innerWidth,
height: window.innerHeight,
};
},
pinType: document.querySelector(".scrollContainer").style.transform
? "transform"
: "fixed",
});
// ! edit here
gsap.to(".left", {
scrollTrigger: {
trigger: ".left",
start: "center top",
scroller: pageContainer,
scrub: true,
},
duration: 1,
x:50
});
ScrollTrigger.addEventListener("refresh", () => scroller.update());
ScrollTrigger.refresh();
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root{
--white:#fff;
}
body{
font-family: 'neue-med';
background-color: #D4C9C9;
}
.container{
padding: 35px;
height: 200vh
}
h4{
letter-spacing: 1px;
display: inline-block;
font-size: 25px;
transition: .2s ease-in;
}
h4:hover{
color: whitesmoke;
cursor: pointer;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/locomotive-scroll.css"
/>
<!-- <link rel="stylesheet" href="/base.css"> -->
<link rel="stylesheet" href="/style.css" />
<title>Document</title>
</head>
<body>
<div class="container scrollContainer">
<div class="sec" data-scroll-section>
<div class="nav">
<div class="nav-text">
<h4 class="left">LOCOMOTIVE.CA</h4>
<h4 class="right" style="float: right">V4.X-EDITION</h4>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.3/gsap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.3/ScrollTrigger.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/locomotive-scroll.min.js"></script>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以基本上我在 h4 上设置了一个未指定的过渡 - 所以基本上是一个全部过渡 - 在 CSS 中,这会干扰 GSAP 的补间。
所以我需要摆脱它或指定应该转换的内容,这样它就不会将 CSS 转换添加到您将在这些元素上使用 GSAP 进行补间的属性。
So basically I have got an unspecified transition set on my h4 - so basically a transition all - in CSS, which is interfering with GSAP's tween.
so I need to either get rid off it or specify what is supposed to be transitioned, so it does not add CSS transitions to properties you are going to tween on with GSAP on those elements.