Jump to content
Search Community

Correct syntax

vickybower test
Moderator Tag

Go to solution Solved by akapowl,

Recommended Posts

Hi

I'm pretty new to GSAP - think its awesome and want to learn more.

I've written this code which works how I want it to - I was just wondering if I could shorten the syntax further by using an array and wanted to know the correct syntax for it.

TIA

Vicky

 

	ScrollTrigger.create({
            trigger: ".panel.four",
            start: "top 75%",
            toggleClass: {targets: "#stats-one", className: "show"},
        });

        ScrollTrigger.create({
            trigger: ".panel.four",
            start: "top 75%",
            toggleClass: {targets: "#stats-two", className: "show"},
        });

        ScrollTrigger.create({
            trigger: ".panel.four",
            start: "top 75%",
            toggleClass: {targets: "#stats-three", className: "show"},
        });

        ScrollTrigger.create({
            trigger: ".panel.four",
            start: "top 75%",
            toggleClass: {targets: "#stats-four", className: "show"},
        });

 

Link to comment
Share on other sites

  • Solution

Hello Vicky, welcome to the GSAP forums!

 

Since your ScrollTriggers do all have the same trigger element and start, you can simply just add multiple targets delimited by a comma, like so:

 

ScrollTrigger.create({
  trigger: ".panel.four",
  start: "top 75%",
  toggleClass: {targets: "#stats-one, #stats-two, #stats-three, #stats-four", className: "show"},
});

 

I changed some things a bit in this demo just for better visibility - btw a minimal demo always helps :) 

 

See the Pen yLPQbRv by akapowl (@akapowl) on CodePen

 

  • Like 3
  • Thanks 1
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...