Jump to content
Search Community

Get Label,Var of specific Second

dazzafact test
Moderator Tag

Recommended Posts

is it possible to give me the variable of a previously defined second?
For example: i want to define id's in the loop for a Timerange.  After i want to call it outside the loop

 

$tl =gsap.timeline({})

var startatText=0;

for(id in arr){ 
    $text[id ] = $('element')
    $tl.fromTo($text[id ] ,{alpha:0,x:($w/2)},{alpha:1,duration:fade},startatText)
    .to($text[id ] ,{duration:textDur},'>')
    .to($text[id ] ,{alpha:0,duration:fade},'>');

    startatText +=textDur+(fade*2);
}

//...

$id=23

var idOfSecond= $tl.time($id)

                    

Link to comment
Share on other sites

This seems very odd to me - the entire point of labels is the exact opposite - they allow you to associate an easy-to-remember label with a particular time. But you're asking to do the opposite, right? You want to know the label that's associated with a particular time? That's totally doable, but I still don't understand any practical usage for that - what would you use that resulting time for? If you're using that to control the playhead going there, why not just use the time in the first place? 

 

function labelAtTime(timeline, label) {
  for (let p in timeline.labels) {
    if (p === label) {
      return timeline.labels[p];
    }
  }
}

Another option is to use the .currentLabel() method: 

timeline.seek(time);
let label = timeline.currentLabel();

Your solution of arr[time] = ids looks a bit odd to me because what if it's a decimal instead of an integer? Typically Arrays are indexed with integers, so it'd be very odd to do something like arr[2.5474]. See what I mean? 

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