Nightshift Posted March 18, 2025 Posted March 18, 2025 Hi There, We're using split text to stagger in the lines of paragraphs. We're experiencing an issue where *some* paragraph get awkward line breaks after splitting the text. The only CSS applied to the text elements are font size, color, line height and letter spacing. We're also following some recommended approaches to wait till fonts load, and to use words along with lines as types. Here's our code: import gsap from "gsap"; import SplitText from "gsap/dist/SplitText"; const splitTextAnimation = () => { document.fonts.ready.then(() => { let splitText: SplitText; function runSplit() { if (splitText) splitText.revert(); splitText = new SplitText("[split-text-animation]", { type: "words, lines", linesClass: "lineChildren", }); } runSplit(); let windowWidth = window.innerWidth; window.addEventListener("resize", () => { if (windowWidth !== window.innerWidth) { windowWidth = window.innerWidth; runSplit(); } }); const texts = document.querySelectorAll("[split-text-animation]"); texts.forEach((text) => { const lines = text.querySelectorAll(".lineChildren"); gsap.fromTo( lines, { opacity: 0, y: 20 }, { opacity: 1, y: 0, stagger: 0.13, scrollTrigger: { trigger: text, start: "top 80%", markers: false, }, }, ); }); }); }; export { splitTextAnimation }; Is there anything in our code that stands out that might be causing an issue? Thanks in advance.
GSAP Helper Posted March 18, 2025 Posted March 18, 2025 Without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates the issue? Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependencies as possible. Start minimal and then incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, at least we have a reduced test case which greatly increases your chances of getting a relevant answer. See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen. that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo: Using a framework/library like React, Vue, Next, etc.? CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: React (please read this article!) Next Svelte Sveltekit Vue Nuxt Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. ✅
Rodrigo Posted March 18, 2025 Posted March 18, 2025 Hi, If you're using custom fonts wait for the fonts to be loaded and rendered before creating the SplitText instance: https://developer.mozilla.org/en-US/docs/Web/API/Document/fonts#doing_operation_after_fonts_are_loaded Hopefully this helps Happy Tweening!
GreenSock Posted March 19, 2025 Posted March 19, 2025 I would also point out that you're only creating your animations on the initial load, but then if the window gets resized, you're re-splitting things but not re-animating them, so the original animations are gonna be animating elements that may not exist anymore (the lines got re-split, thus new elements created). So be careful with that. If you want more help, please make sure you include a minimal demo, like a CodePen that clearly illustrates the issue.
Solution Nightshift Posted March 19, 2025 Author Solution Posted March 19, 2025 the following CSS setting seemed to resolve the issue: .lineChildren { display: inline-block !important; width: auto !important; } Thanks all 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now