Jump to content
Search Community

How to add multiple classes in GSAP animation Code

SuperHero test
Moderator Tag

Recommended Posts

Hello There,

 

Could you please guide me to add multiple classes in one line.

 

Here is the code.

.to(".white1", {opacity: 1})
.to(".white2", {opacity: 1})
 .to(".white3", {opacity: 1}) 
.to(".white4", {opacity: 1})

 

--------
 

Example: .to(".white1", ".white2", ".white3", ".white4", {opacity: 1}) - Not sure this is correct code or not.

 

I need to display white colar at same time instead of coming one-by-one.

 

Thanks in advance.

 

Harshal Vanarse.

Link to comment
Share on other sites

Hey Harshal.

 

There's a few ways to do this. The easiest is to use a shared class (assuming you can change the HTML):

.to(".white", {opacity: 1})

The next is to use a more complex selector string:

.to(".white1, .white2, .white3, .white4", {opacity: 1})

Then you can also use an array of values, granted the values are of the same type (DOM element, selector string, etc.):

.to([".white1", ".white2", ".white3", ".white4"], {opacity: 1})

You could also use an attribute selector:

.to("[class*='white']", {opacity: 1})

 

Happy tweening :) 

  • Like 6
Link to comment
Share on other sites

  • 3 months later...
  • 1 year later...

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