Jump to content
GreenSock

TimelineLite

.totalDuration()

.totalDuration( value:Number ) : *

[override] Gets the timeline's total duration or, if used as a setter, adjusts the timeline's timeScale to fit it within the specified duration.

Parameters

value: Number

(default = NaN) — Omitting the parameter returns the current value (getter), whereas defining the parameter sets the value (setter) and returns the instance itself for easier chaining.

Returns : *

Omitting the parameter returns the current value (getter), whereas defining the parameter sets the value (setter) and returns the instance itself for easier chaining.

 

Details

Gets the timeline's total duration or, if used as a setter, adjusts the timeline's timeScale to fit it within the specified duration. For example, if a TimelineMax instance has a duration of 2 and a repeat of 3, its totalDuration would be 8 (one standard play plus 3 repeats equals 4 total cycles).

Due to the fact that a timeline's totalDuration is dictated by its contents, using this method as a setter will simply cause the timeScale to be adjusted to fit the current contents into the specified totalDuration. For example, if there are 20-seconds worth of tweens in the timeline and you do myTimeline.totalDuration(10), the timeScale would be changed to 2. If you checked the totalDuration again immediately after that, it would still return 20 because technically that is how long all the child tweens/timelines are but upon playback the speed would be doubled because of the timeScale.

This method serves as both a getter and setter. Omitting the parameter returns the current value (getter), whereas defining the parameter sets the value (setter) and returns the instance itself for easier chaining, like myAnimation.totalDuration(2).play(1);

var ctd = myAnimation.totalDuration(); //gets current total duration
myAnimation.totalDuration( 20 ); //adjusts the timeScale so that myAnimation fits into exactly 20 seconds on its parent timeline
Copyright 2017, GreenSock. All rights reserved. This work is subject to theterms of useor for Club GreenSock members, the software agreement that was issued with the membership.
×