Jump to content
Search Community

splitText implementation

ansuft test
Moderator Tag

Recommended Posts

Hi, I have this part of a slide code: 

    

  function nextSlide(pageNumber) {
    const nextPage = pages[pageNumber];
    const currentPage = pages[current];
    const nextText = nextPage.querySelector("h1");


    const tl = new TimelineMax({
      onStart: function() {
        slides.forEach(slide => {
          slide.style.pointerEvents = "none";
        });
      },
      onComplete: function() {
        slides.forEach(slide => {
          slide.style.pointerEvents = "all";
        });
      }
    });

    tl.fromTo(
        currentPage,
        0.3,
        { opacity: 1, pointerEvents: "all" },
        { opacity: 0, pointerEvents: "none" }
      )
      .fromTo(
        nextPage,
        0.3,
        { opacity: 0, pointerEvents: "none" },
        { opacity: 1, pointerEvents: "all" },
        "-=0.6"
      )
     fromTo(nextText, 0.3, { opacity: 0, y: 0 }, { opacity: 1, y: 0 });

      current = pageNumber;
  }

 

And I don't know how to implement a splitText in 'h1' (nexText) like here:

In particular, I don't know how to make these two parts combine:


const nextText = nextPage.querySelector ("h1");
and
var mySplitText = new SplitText ("# quote", {type: "chars, words, lines"})

See the Pen aVJRBg by GreenSock (@GreenSock) on CodePen

Link to comment
Share on other sites

6 hours ago, vidi45 said:

I don't know how to make these two parts combine:


const nextText = nextPage.querySelector ("h1");
and
var mySplitText = new SplitText ("# quote", {type: "chars, words, lines"})

I'm not sure I understand your question, but I assume you wanted something like this?: 

 

var mySplitText = SplitText.create(nextPage.querySelector("h1"), {type: "chars, words, lines"});

?

 

If you still need some help, it'd be best to provide a reduced test case in a codepen or something so that we can see the issue in context. 

 

Happy tweening!

Link to comment
Share on other sites

2 hours ago, vidi45 said:

It does not work for me. 

Here is my slide.  I can't make the (.destails h1) splitText

The first thing you need to do is split the text on load: 

pages.forEach((page, index) => {
  page.splitText = new SplitText (page.querySelector("h1"), {type: "chars, words"});
});

Then inside of the nextSlide function you just need to animate the split text however you want to. For example you could add something like this to the timeline:

.staggerFrom(nextPage.splitText.chars, 0.3, {y:20, opacity:0, stagger: 0.04})

We highly recommend switching over to GSAP 3 - it has a smaller file size, improved API, and a bunch of new features! 

See the Pen zYxXoGQ?editors=0010 by GreenSock (@GreenSock) on CodePen

  • Like 1
Link to comment
Share on other sites

11 minutes ago, vidi45 said:

Where specifically is it 'on load'? in the init function?

Yep.

 

11 minutes ago, vidi45 said:

I put it and it doesn't work even the slide

If you look in your dev tool's console, you will see an error: "SplitText is not defined". You must load SplitText. 

 

11 minutes ago, vidi45 said:

Do I have to remove this?
const nextText = nextPage.querySelector (". details h1");

.fromTo (nextText, 0.3, {opacity: 0, y: 0}, {opacity: 1, y: 0}

Nope.

Link to comment
Share on other sites

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...