-
Notifications
You must be signed in to change notification settings - Fork 757
Description
Problem
Currently, when you write an animation based on a ScrollTimeline, you have to provide an arbitrary animation duration, e.g.:
document.getElementById('parallax').animate(
{ transform: ['translateY(0)', 'translateY(100px)']},
{ duration: 10000, // Totally arbitrary!
fill: 'both',
timeline: new ScrollTimeline({
endScrollOffset: '200px'})
});By default, ScrollTimeline's auto value for effective scroll range will assume the range of the animation. This means that whatever duration is supplied, scroling from (in this case) 0px to 200px will advance the animation from 0 to 100%. Even worse, having too small of a value entered for duration can result in precision problems (see #4353) due to the microsecond precision on animation timers.
Proposal
Allow omitting the duration for an animation driven by finite timeline.
Concretely:
- Introduce a finite timeline type - whose range must not be infinite.
- If the animation timeline is finite (i.e. ScrollTimeline is finite, DocumentTimeline is not as it has no end value), duration may be omitted for new animations.
- When duration is omitted, the duration will be set to the end value for the timeline.
- If the timeline has timeRange
auto, the animation and timeline will have a duration / timeRange of 100 (i.e. 100%).
- If the timeline has timeRange
For the above example, this would make the following valid:
document.getElementById('parallax').animate(
{ transform: ['translateY(0)', 'translateY(100px)']},
{ fill: 'both',
timeline: new ScrollTimeline({
endScrollOffset: '200px'})
});And would result in a duration and timeRange of 100 (percent).
Open questions
- Is there a better way to express the non-time based progress fallback? i.e. For ScrollTimeline we could use pixels.
- Are the precision requirements on non time based animations different than time based animations? If not, the default time range for progress animations needs to be large enough to be precise.
Note: This is technically a change of the web-animations, but the reasons for it are due to finite timelines such as ScrollTimeline.
@birtles @graouts @majido WDYT? I can put together a prototype of this in my polyfill and include other examples if it would be helpful.