lukePeavey / SplitType

Javascript utility that splits text into lines, words, characters for animation
https://lukepeavey.github.io/SplitType/
545 stars 39 forks source link

SplitType not including some spaces #68

Closed wtem-design closed 9 months ago

wtem-design commented 9 months ago

Hi

I'm splitting texts into words, and some spaces are lost in the process but not all. If you open the menu in https://immosolid-staging-cd58a2c892d12f4668483.webflow.io/ 'Aktuelle Angebote' has a missing space, and the smaller links ('Informationen für Eigentümer') have the first space present but the second missing. If I revert splitType, spaces come back. For testing, I tried to split h1 on the same page and had no issue with the spaces. I animate with gsap.

lukePeavey commented 9 months ago

Could you include the relevant source code for the menu component where this issue is occurring (or link to the source code for the project if it's on GitHub).

what other libraries / frameworks / are use using?

wtem-design commented 9 months ago
document.addEventListener("DOMContentLoaded", () => {

  let menuButton = document.querySelector('.navbar_hamburger-button');
  const menuLinks = SplitType.create('.navbar_hamburger-primary-link, .navbar_hamburger-secondary-link', { types: 'words' });

  let openNavbar = gsap.timeline({
    paused: true,
    reversed: true,
    defaults: {
      duration: 1.5,
      ease: "expo.inOut"
    }
  });

  openNavbar.set('.navbar_hamburger-menu', { display: 'grid' })
            .set('body', { overflow:'hidden' })
            .fromTo('.navbar_hamburger-menu-image', { xPercent: 30, scale: 1.3, opacity: 0 }, { xPercent: 0, scale: 1, opacity: 1})
            .fromTo('.navbar_hamburger-menu-links-background', { width: 0 }, { width: 'auto' }, '<')
            .fromTo('.navbar_hamburger-menu-kontakt-background', { width: '0%' }, { width: '100%' }, '<')
            .from( menuLinks.words, { opacity: 0, yPercent: 100, stagger: { amount: 0.2 } }, '<');

  menuButton.addEventListener('click', function () {
    openNavbar.reversed() ? openNavbar.play() : openNavbar.reverse();
  });

});

Besides splittype and gsap (base + scrolltrigger) only library uploaded to the page is splide. I use splittype on my h1 and h2 across the site without the described problem, under different URL: https://immosolid-staging.webflow.io/, in there the menu links look fine, but it's because added margin to the spans.

lukePeavey commented 9 months ago

Thanks. I will take a look at this today

lukePeavey commented 9 months ago

Have you try removing any animations /transitions that are applied to those elements and just splitting the text?

wtem-design commented 9 months ago

Well now secondary links have all spaces, but primary link still does not. All have been split into words.

Zrzut ekranu 2023-11-24 o 14 42 48
lukePeavey commented 9 months ago

Did you try remove any animations / styles that are applied to those elements ?

lukePeavey commented 9 months ago

Also, try splitting into words and characters, see if that makes a difference

wtem-design commented 9 months ago

The whole js I've written for this page looks now like this:

<script src="https://unpkg.com/split-type"></script> <script> document.addEventListener("DOMContentLoaded", () => { const menuLinks = SplitType.create('.navbar_hamburger-primary-link, .navbar_hamburger-secondary-link', { types: 'words, chars' }); }); </script>

Split into characters as well, but it still looks as on the screen.

lukePeavey commented 9 months ago

You could try creating a codepen or codeSandbox, using the same html structure as the menu on your site, the same css, animations, and JavaScript, to see if this issue can be reproduced outside of WebFlow.

wtem-design commented 9 months ago

Okay found it – splitted text of links had display:flex set. Without it splitting works perfect.

Thanks for your time and the plugin!

lukePeavey commented 9 months ago

Ah! I'm glad you figured it out!