Hello everyone and happy holidays
I have two questions:
The first one is:
I have two horizontal sliders and I want all the sliders to stop working and become vertical elements when the size is less than 1024 pixels. I looked through a couple of questions about this and saw that some of them are already outdated, since a couple of things have changed in Gsap 3, and I couldn't figure out the others. Please tell me how to resize to disable the animation as described in the documentation and re-run it at the desired window size?
Second:
I have recently started learning Gsap and it seems to me all the time that I am doing the animation wrong, please review my code and let me know where to fix it. I will be very grateful for any idea.
P.s Sorry, I couldn't make you a demo version on codepen because I work at vue and have already broken the project into small parts.
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
gsap.registerPlugin(ScrollTrigger);
const tl = gsap.timeline();
let ww = window.innerWidth;
let sections = gsap.utils.toArray(".panel");
let container = document.querySelector(".wrap");
function mainPage() {
tl.to(".boxes", {
duration: 5,
ease: "none",
x: -ww,
repeat: -1,
});
console.log(">>>>>One<<<<<");
gsap.to(sections, {
xPercent: -100 * (sections.length - 1),
ease: "none",
scrollTrigger: {
trigger: container,
pin: true,
scrub: 1,
snap: 1 / (sections.length - 1),
invalidateOnRefresh: true,
end: () => "+=" + container.offsetWidth,
},
});
//! Two
let customContainer = document.querySelector(".customContainer");
gsap.to(customContainer, {
x: () =>
-(customContainer.scrollWidth - document.documentElement.clientWidth) +
"px",
ease: "none",
duration: 4,
scrollTrigger: {
// markers: true,
trigger: ".trigger",
invalidateOnRefresh: true,
pin: true,
scrub: 1,
// snap: 1,
end: () => "+=" + customContainer.offsetWidth,
},
});
}
document.addEventListener("DOMContentLoaded", adaptive);
window.addEventListener("resize", function () {
adaptive();
ScrollTrigger.refresh();
});
function adaptive() {
return window.innerWidth > 1024 ? mainPage() : console.log("TWO");
}