Jump to content
Search Community

Combining the demo Typewriter effect with ScrollTrigger

Detrol
Moderator Tag

Go to solution Solved by Detrol,

Recommended Posts

Posted

Hey!

 

So i love the demo typewriter, as in the one found here

 

But, how can i combine it with scrolltrigger, so it will start "typing" when i scroll down to that section, and not as soon as i load the page?

 

Thank you in advance!

See the Pen RwBwJBm by GreenSock (@GreenSock) on CodePen.

  • Solution
Posted

I got it sorted after some sleep. Wasn't so difficult, just a tired brain.

const myTextElement = document.getElementsByClassName("jag-decoy");
const timePerCharacter = 0.02;

gsap.to(".jag", {
    scrollTrigger: {
        trigger: ".jag",
        toggleActions: "play",
        start: "top 90%",
        end: "bottom 50%+=100px",
    },
    text: {
        value: myTextElement[0].innerHTML
    },
    duration: myTextElement[0].innerText.length * timePerCharacter,
    delay: 0.5,
    ease: "none",
    delimiter: " "
})

 

  • Like 3

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...