Hi Emily,
I have some suggestions for improvements for your demo.
Issues
First of all you don't need GSAP to change the position of your element, you can simply specify this in the stylesheet.
.next-post {
...
}
@media screen and (max-width: 579px) {
.next-post {
position: fixed;
visibility: hidden;
...
}
}
Also you don't need the resize event listener, in your demo you are creating a new ScrollTrigger every-time the user resizes the window. Try slowly resize on the smaller screens and you will see multiple ScrollTrigger markers being added to the DOM.
Solution
Use ScrollTrigger matchMedia, this is a great way to specify a breakpoint in your JS file and create trigger only for that breakpoint.
ScrollTrigger.matchMedia({
// small screen that matches your CSS break point
"(max-width: 579px)": function () {
// setup animations and ScrollTrigger if the link exists
if (nextPost) {
// simple tween, you don't need a timeline
gsap.to(nextPost, {
duration: 0.5,
autoAlpha: 1,
scrollTrigger: {
trigger: ".column",
toggleActions: "restart pause reverse pause",
start: "bottom 80%",
// specify which element should trigger the end of your animation
endTrigger: "main",
end: "bottom 100%",
scrub: true,
markers: true
}
});
}
},
// larger screen
"(min-width: 580px)": function () {
// remove any inline styles from the nextPost button
// I thought this would be done automatically by ScrollTrigger but it didn't
gsap.set(nextPost, { clearProps: "all" });
}
});
Use autoAlpha to show/hide your link. GreenSock's autoAlpha combines opacity and visibility in one handy property. If you only use opacity, the link is not showing to the user, but is still clickable in the browser and might result in users accidentally clicking on it.
In the large breakpoint I did use the clearProps to remove all inline styles set in the smaller breakpoint.
gsap.set(nextPost, { clearProps: "all" });
Here is the demo
https://codepen.io/ihatetomatoes/pen/VwaWojw
Feel free to adjust the ending values.
Cheers
Petr