Jump to content
Search Community

GSAP timeline control with js

tash2020 test
Moderator Tag

Recommended Posts

Hi @tash2020,

 

There are quite a few syntax errors in your code, to start. Semicolons, while not required, should be used ... it helps to understand the code better.

 

And then there are a few logic and structure issues. First thing I'll point out is your goal is to compare certain dates to the current date ... but there is not current date established anywhere. Putting that aside and using some created dates, we can move onto the other issues.

 

If you want the timeline to play only if conditions are met, it's easier to use the pause property when constructing the timeline.

 

const tldot = gsap.timeline( { repeat: -1, paused: 1 } );

 

This block is not closed properly, and you can't compare three items in this way. You'd have to create a function that takes 3 (or more) values and does the comparison and returns true/false.

 

const isBlinking = (date1, date2, date3) => {
  if(date1.getFullYear() === date2.getFullYear() === date3.getFullYear() &&
    date1.getMonth() === date2.getMonth() === date3.getMonth() &&
 date1.getDate() === date2.getDate() === date3.getdate())
tldot.play();
} else {
tldot.pause();
}

 

Here is a codeine addressing these issues.

 

See the Pen jObvXbK?editors=1111 by sgorneau (@sgorneau) 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...