Jump to content
Search Community

Creating a progress bar...

Black Ducas test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

10 hours ago, GSAP Helper said:

Without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependancies as possible. Start minimal and then incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

 

Here it is

 

The error I said is on the Codepen too:

image.thumb.jpeg.0f29ef35e68f06620183b2414e4253dd.jpeg

 

 

Orignal topic 

 

Quote

Hi, I'm trying the quoted code.

function progressBarUpdate(tween) {
  console.log(tween.progress())
}

const tl = gsap.timeline({
  delay: 1,
  onUpdate: progressBarUpdate,
});
tl
  .add(animate())
  .add(reveal(), 'reveal')
  .add(start())

 

The timeline itself works perfectly. I just added onUpdate: progressBarUpdate and the function, and I get this error:

  Quote

Uncaught TypeError: Cannot read properties of undefined (reading 'progress')
    at Timeline.progressBarUpdate [as _onUpdate]

The problem comes from this line console.log(tween.progress())

 

Any idea?

 

See the Pen dyrqqPy?editors=1111 by gooogooo (@gooogooo) on CodePen

Link to comment
Share on other sites

Hi @Black Ducas I've split your reply to its own topic, no need to bother all these people 9 years later. 

 

If you would have logged tween you would see that you don't have access to it, because you never pass it to the function that you call in onComplete

 

If you pass the current timeline as an argument to the function, you do have access to it. Check out how functions work in Javascript https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions Hope it helps and happy tweening! 

 

See the Pen oNVPPxN?editors=0011 by mvaneijgen (@mvaneijgen) on CodePen

  • Like 1
Link to comment
Share on other sites

  • Solution

Yeah probably something has changed 9 years later, no worries. It is always a good idea to log the things you get to make sure they are what you think they are. 

 

In this case you can do two things. You want to tween a timeline, so all the logic should move to the timeline. Pausing a tween and then controlling the timeline is what is tripping you up here. 

// With a timeline 
let progressBarTl = gsap.timeline({
    paused: true, // Timeline gets paused
})
progressBarTl.from(".progress-bar", {
  scaleX: 0,
  duration: 2,
  ease: "none"
});

// Using a single tween
const progressBarTl = gsap.from(".progress-bar", {
  paused: true, // Tween gets paused
  scaleX: 0,
  duration: 2,
  ease: "none"
});

See the Pen QWoVZEP?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen

 

Hope it helps and happy tweening! 

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