dazzafact Posted February 25, 2022 Share Posted February 25, 2022 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 More sharing options...
GreenSock Posted February 25, 2022 Share Posted February 25, 2022 Hi @dazzafact. I read your question a few times but I'm totally lost. Can you please rephrase the question and maybe provide a minimal demo? I don't understand what you're trying to do. Link to comment Share on other sites More sharing options...
dazzafact Posted February 25, 2022 Author Share Posted February 25, 2022 Yes, i try. How i can get a var/Label of a specific TIme? $id=$tl.time(23).label('id') (which i have defined previously) ?? A demo? mhhh i even dont know how o solve this 😅 $tl.time($id) $tl.time($id) Link to comment Share on other sites More sharing options...
dazzafact Posted February 25, 2022 Author Share Posted February 25, 2022 Ok, i have found a solution. I thought Labels could be fix my problem also. No Problem. i just build another array arr[time]=ids Link to comment Share on other sites More sharing options...
GreenSock Posted February 25, 2022 Share Posted February 25, 2022 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 More sharing options...
dazzafact Posted February 26, 2022 Author Share Posted February 26, 2022 Hey, thanks! i think this was what iam looking for:timeline.seek(time); let label = timeline.currentLabel(); Â Many Thanks 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now