Jump to content
Search Community

Array of target objects

iconofsyn test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

The documentation for things like the tweenlight/max constructors and methods such as from(), to() ect all say they can accept an object or array of objects as their target property.

I have 2 questions both regarding passing an array of objects

 

1)
If a Jquery selector is used and it matches multiple objects (ie $('.className')) is this valid input for greensock?

(the green sock code for this may look something like this)
 

TweenMax.to($('LI'),2,{opacity:0.5});

 

2)
If not using jquery what format does the array need to take, would the following code be valid

var objects = [];
objects.push(document.getElementById('someDiv'));
objects.push(document.getElementById('someOtherDiv'));
objects.push(document.getElementById('someThirdDiv'));

TweenMax.to(objects,2,{opacity:0.5});

 

Link to comment
Share on other sites

Hi @iconofsyn :)

 

Welcome to the forum.

 

Using jQuery like example #1 will work just fine. You can also write it like this:

TweenMax.to(".someClass", 2, {opacity:0.5});

 

Pushing the elements into an array like your example #2 is fine too. You can also do something like this:

TweenMax.to("#someDiv, #someOtherDiv, #someThirdDiv", 2, {opacity:0.5});

 

GSAP is quite flexible so there are always many ways of achieving the same result. It all depends on what meets your needs the best. When in doubt if something will work just set up a CodePen and give it a try.

 

Happy tweening and welcome aboard.

:)

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