What you do evokes the most wonderful feelings.
Thank you for helping people like me.
I've been working with gsap for a short time, but I've already fallen in love with this plugin.
New demo: https://codepen.io/bysobi/pen/MWLOMXR
I hope our code, which we created, will help someone in the same way.
I made a few improvements to your code, specifically:
1. Ensured that the last element does not disappear by adding a condition (not sure if this is an "elegant" solution):
items.forEach((item, i) => {
tl.to(
[
item.querySelector(".scroll-content-item__text"),
item.querySelector(".scroll-content-item__image")
],
{
duration: 0.3,
ease: "power1.inOut",
yPercent: 0,
opacity: 1,
}
);
if (i < items.length - 1) {
tl.to(
item.querySelector(".scroll-content-item__text"),
{
duration: 1,
yPercent: -30,
opacity: 0
},
);
tl.set(item.querySelector(".scroll-content-item__image"), {
opacity: 0,
ease: "power1.inOut"
});
}
});
2. After completing the animation for the first .scroll-content-item block, the image now smoothly transitions to another.
We almost 1:1 copied the block from the Apple website.
I achieved this thanks to the CSS property that I added for the .scroll-content-item__image class:
transition: opacity .3s ease-in;
Before that, I removed opacity: 0.
However, this caused a problem that I can't solve yet. Because I removed opacity: 0, the images are displayed BEFORE the animation triggers.
If I set opacity: 0, I can't achieve the smoothness I need.
Any ideas?
3. How can I make the animation start from the middle of the screen? When I change the "Start" parameter, the block is not displayed in the center in this case.