我们尝试用gsap/scrollTrigger动画(播放)Lottie文件。滚动效果很好,直到我到达我们应该使用scrollTrigger来动画一些元素的部分。
- 我们尝试了gsap/lottie辅助函数
- 我们尝试从Chriss Gannon滚动Lottie
这是我们现在的代码。您可以简单地将这些代码片段放在codepen中使用它们。或者如果你想让它更容易搜索我的名字amini-py
在codepen。
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.4/gsap.min.js" integrity="sha512-VEBjfxWUOyzl0bAwh4gdLEaQyDYPvLrZql3pw1ifgb6fhEvZl9iDDehwHZ+dsMzA0Jfww8Xt7COSZuJ/slxc4Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.4/ScrollTrigger.min.js" integrity="sha512-v8B8T8l8JiiJRGomPd2k+bPS98RWBLGChFMJbK1hmHiDHYq0EjdQl20LyWeIs+MGRLTWBycJGEGAjKkEtd7w5Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.jsdelivr.net/npm/@lottiefiles/[email protected]/dist/lottie-interactivity.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@lottiefiles/lottie-[email protected]/dist/lottie-player.min.js"></script>
<div class="wrapper-child">
<div class="child">
<h5>First</h5>
<p>lorem ipsum sit amet sssssssssssssssssssssss</p>
</div>
<div class="child">
<h5>Second</h5>
<p>lorem ipsum sit amet sssssssssssssssssssssss</p>
</div>
<div class="child">
<h5>Thirds</h5>
<p>lorem ipsum sit amet sssssssssssssssssssssss</p>
</div>
<div class="child">
<h5>Fourth</h5>
<p>lorem ipsum sit amet sssssssssssssssssssssss</p>
</div>
<div class="child">
<h5>Fifth</h5>
<p>lorem ipsum sit amet sssssssssssssssssssssss</p>
</div>
</section>
width: 90vw;
height: 250px;
overflow-y: hidden;
display: flex;
}
.wrapper-child {
border: 1px solid red;
width: 50%;
}
LottieInteractivity.create({
player: "#firstLottie",
mode: "scroll",
actions: [
{
visibility: [0, 1.0],
type: "seek",
frames: [0, 300]
}
]
});
gsap.registerPlugin(ScrollTrigger);
const sections = gsap.utils.toArray(".child");
gsap.to(sections, {
yPercent: -100 * (sections.length - 1),
ease: "none",
scrollTrigger: {
trigger: ".wrapper",
pin: true,
scrub: 1,
start: "top center",
end: () => "+=" + document.querySelector(".wrapper").offsetHeight
}
});
2条答案
按热度按时间zbq4xfa01#
GSAP不是必需的。我建议使用浏览器的Intersection Observer API
工作演示:https://codepen.io/rabelais88/pen/NWYRXdJ
2skhul332#