Jump to content
Search Community

Using a variable in Modifiers plugin

celli test
Moderator Tag

Go to solution Solved by Cassie,

Recommended Posts

I picked up the GSAP demo using the modifiers plugin, and I wanted to replace the number of the total width of the boxes in the carousel, with a variable called 'boxesLength' since I won't know how many boxes there will be. The number of boxes will change, so I wouldn't want to use a static number. Is it possible to use a variable like I have in my codePen ?

See the Pen BawpVwd by celli (@celli) on CodePen

Link to comment
Share on other sites

  • Solution

Definitely - but you'll need to get the length of ALL the boxes

 

// bad - just getting one box
let boxLength = document.querySelector(".box").length;

// good - gets the length of an array of boxes
let boxLength = document.querySelectorAll(".box").length;

 

  • Like 1
Link to comment
Share on other sites

I noticed one thing while inspecting and working with the demo — if I change the duration to something other than 1 (let's say .9) then the sync of the scrolling elements gets thrown off, you need to wait until the 7th or 8th element to scroll to see it.

Is there a way to compensate for a duration other than 1 ? You will see in my codePen I made some adjustments.

Link to comment
Share on other sites

Hi Cassie,

 

yes, 0.1 seems to work actually—did you try .9 ? The boxes eventually skip (usually at the 7th or 8th slide)... let me know if you see that happening? I changed it on your forked codePen and I get the same result

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