Hello! I have recently encountered a problem where I am trying to revert the parent divs after a browser resize, but it is not reverting at all!
I am trying to revert the "paragraph-" and "headerParentSplit" before the animation starts (as long as it has been set before) I have tried debugging by console logging this if statement, and it does go through, although it still does no difference.
First picture with only one header line, is how it should look like. This is what happens when you enter the website with a fullscreen resolution. The other picture with a red and black background for the header, is how it looks like. The reason behind this is that the div is split into lines when the resolution was smaller (therfore it is two divs). It does not revert with the following code..
function setupSplits() {
const paragraph = document.querySelectorAll("p");
const header = document.querySelectorAll("h1, h2");
if (headerParentSplit != null) {
headerParentSplit.revert();
paragraphParentSplit.revert();
}
var headerParentSplit = new $SplitText(header, {
// type: "words",
linesClass: "split-parent",
});
var paragraphParentSplit = new $SplitText(paragraph, {
// type: "words",
linesClass: "split-parent",
});
header.forEach((header) => {
// Reset if needed
if (header.anim) {
header.anim.progress(1).kill();
header.split.revert();
}
header.split = new $SplitText(header, {
type: "lines,words",
linesClass: "split-line",
});
// Set up the anim
$gsap.set("h1, h2", {
visibility: "visible",
});
header.anim = $gsap.from(header.split.words, {
scrollTrigger: {
trigger: header,
toggleActions: "restart pause resume reverse",
start: "top 95%",
},
duration: 0.7,
ease: "circ.easeOut",
yPercent: 100,
opacity: 0,
stagger: 0.015,
});
});
paragraph.forEach((paragraph) => {
// Reset if needed
if (paragraph.anim) {
paragraph.anim.progress(1).kill();
paragraph.split.revert();
}
paragraph.split = new $SplitText(paragraph, {
type: "lines,words,chars",
linesClass: "split-line",
});
$gsap.set("p", {
visibility: "visible",
});
paragraph.anim = $gsap.from(paragraph.split.words, {
scrollTrigger: {
trigger: paragraph,
toggleActions: "restart pause resume reverse",
start: "top 95%",
},
duration: 0.6,
ease: "circ.easeOut",
yPercent: 100,
opacity: 0,
stagger: 0.005,
});
});
}
onMounted(() => {
setupSplits();
$ScrollTrigger.addEventListener("refresh", () => {
setupSplits();
});
});