Re: [web-animations] Please, provide examples for AnimationReadonly usage

On 2015/03/06 19:19, Aleksei Semenov wrote:
> Hello, everyone.
>
> The specification defines two interfaces: AnimationReadonly and Animation.
> First one is read-only, second is mutable.
> https://w3c.github.io/web-animations/#the-animation-interfaces
>
> The examples in the specification refer only to Animation interface.
> So it is not clear, what is a purpose of AnimationReadonly interface.
> Could you clarify this?

The purpose for the KeyframeEffectReadonly interface (and other similar 
interfaces) is for exposing animations created by CSS / SVG etc.

If an animation corresponds to a CSS animation for example, what is the 
expected behavior when the author changes its duration?

It can't update the stylesheet that generated it because that might 
affect many other animations too.

Trying to make it update the local style of the target element proves 
very difficult too because if you make independent changes to the style 
sheet and the API you will run into trouble because, suppose you add an 
animation to your 'animation' property in the stylesheet, you may get 
surprising results because the 'animation-duration' stored as local 
style has a different list length now.

Trying to say, "properties explicitly set through the API override those 
set by style" creates a very confusing API because then authors need a 
way to inspect which properties are overridden locally and which are 
from style and they need a means for resetting properties to track 
changes to style. We tried this and it was horrible.

The approach we have now is that animations created by CSS (and I expect 
SVG too) produce an Animation whose target effect is a 
KeyframeEffectReadonly object.

You can perform play control on the Animation such as pausing/reversing 
etc. without breaking the connection with style. If, however, you want 
to modify the duration of the animation or any of the other properties 
on the KeyframeEffectReadonly object, you need to explicitly break the 
link with style as follows:

   anim.effect = anim.effect.clone();

Any changes to the cloned KeyframeEffect don't affect style and any 
changes to style only affect the old KeyframeEffectReadonly object which 
is now irrelevant.

The only place where style overlaps with changes to the API is pausing 
and animation-play-state but since this is simply a binary state we can 
work out some sensible rules to allow this to behave intuitively.

So, in summary, we don't expect script authors to create 
KeyframeEffectReadonly objects typically although there may be some use 
cases where it is useful. It's main purpose is to be used to expose 
animations created through declarative means.

Best regards,

Brian

Received on Thursday, 9 April 2015 07:03:45 UTC