How to get current keyframes time and lastkeyframetime?

161 views Asked by At

How can I get currentKeyframeTime & lastKeyframeTime in any animation using Javascript?

I want to update the currentKeyframeTime of my animation to some other time because i'm making a tracking bar for animation, similar to a player slider like in youtube so I need the currentKeyframeTime and lastKeyframeTime.

I have successfully done this for audio, as it has currentTime & duration type properties. What code I should write to get currentKeyframeTime & lastKeyFrameTime?

1

There are 1 answers

0
Kevin F On

You would keep track of the time elapsed like so: http://plnkr.co/edit/CfOttpMPelxS1iYnnEPW

(function(){
  var currentFrame, startTime;

  function animate(){
      console.log('Previous Frame Happened At: ' + currentFrame);
      currentFrame = Date.now() - startTime;
      console.log('Current time elapsed since start: ' + currentFrame);
      requestAnimationFrame(animate);
  }

  startTime = Date.now();
  currentFrame = startTime;
  requestAnimationFrame(animate);
})();