User:Mantaroh/Scroll-driven animations: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(Update sample code)
(Update category and details.)
Line 1: Line 1:
'''** Note : This Document is WIP **'''
'''** Note : This Document is WIP(Doesn't translate yet.) **'''


== Scroll-driven animations. ==
== Scroll-driven animations. ==
For previous discussion, see [[Platform/Layout/Extended Timelines|Extended Timeline]].
For previous discussion, see [[Platform/Layout/Extended Timelines|Extended Timeline]].


=== Background ===
=== Introduction ===
We shipped wrietable timeline (bug 1178662) on Firefox 49, then we can set the new timeline instead of default document timeline. And we can extend AnimationTimeline.
Dean proposed [https://lists.w3.org/Archives/Public/www-style/2014Sep/0135.html| the features of animation-trigger / animation-timebases / animation-behavior].<br/>
And, Brian/Botond proposed the [[Platform/Layout/Extended Timelines|Extended Timeline]].<br/>
Thease ideas is similar to each idea.
特に、スクロール量とタイムラインの値をマッピングさせることについては非常に似ているため、お互いの仕様を共通化させることで、
CSS / Web Animation に適用したアーキテクチャを構築することが可能になります。
また、Firefox 49 から有効になった Bug 1178662「wrietable timeline」のバグで、タイムラインの設定 / 構築が容易に行えるようになったことから
ScrollTimeline のようにスクロール量とマッピングされたタイムラインを作成することが可能になりました。


e.g.
そのため、このドキュメントでは Web Animation / CSS Animation を考慮したスクロールベースのアニメーションについて記述しています。
var timeline = new DocumentTimeline(10); // origin time is 10 ms. ([https://w3c.github.io/web-animations/#origin-time| Origin time spec])
var animation = new Animation(new KeyframeEffect(div, { marginLeft: ['0px', '200px'] }, 10000), null);
animation.timeline = timeline;
 
After landed this feature, we can implement ScrollTimeline/MediaTimeline..etc.
 
=== Interface proposal ===
Same as ScrollTimeline, we should set ScrollTimeline to timeline property of animation.


=== Interface of script proposal ===
Same as DocumentTimeline, we should set ScrollTimeline to timeline property of animation.<br/>
Perhaps, WebIDL of ScrollTimeline is same to [[Platform/Layout/Extended|previous API proposal]].
Perhaps, WebIDL of ScrollTimeline is same to [[Platform/Layout/Extended|previous API proposal]].


  [Constructor ((Window or Element) scrollSource, Orientation orientation)
  [Constructor ((Window or Element) scrollSource, Orientation orientation, optional DOMString maxTime)
  interface ScrollTimeline : AnimationTimeline {
  interface ScrollTimeline : AnimationTimeline {
   attribute Orientation orientation;
   attribute Orientation orientation;
  attribute DOMString maxTime;
  };
  };
   
   
  // Is there an existing enum somewhere we can use for this?
  // Is there an existing enum somewhere we can use for this?
  enum Orientation { "vertical", "horizontal" };
  enum Orientation { "vertical", "horizontal" };
コンストラクタの第3引数の maxTime は、アニメーションの繰り返し回数が無限(Infinte)の為に使用します。
この引数を指定しない場合は、以下の計算により自動で設定されます。
- もし ScrollTimeline に関連する Aniamtion が存在しない場合は 0ms
- Animation が存在する場合、[https://w3c.github.io/web-animations/#target-effect-end| target effect end]
  - 値が Inifinity の場合、関連する Animation で一番大きな target effect end とする。
  - 関連するすべての Animation の target effect end が Infinity の場合、
   
=== Interface of CSS proposal ===


=== Usage of this API ===
=== Usage of this API ===
var scrollTimeline = new ScrollTimeline(div, "vertical");
1) Duration of animation is finite.
var animation = new Animation(new KeyframeEffect( { marginLeft: ['0px', '200px'] }, 10000), null);
  var scrollTimeline = new ScrollTimeline(div, "vertical");
animation.timeline = scrollTimeline;
  var animation1 = new Animation(new KeyframeEffect( { marginLeft: ['0px', '200px'] }, 10000), null);
  var animation2 = new Animation(new KeyframeEffect( { marginLeft: ['100px', '300px'] }, 20000), null);
  animation1.timeline = scrollTimeline;
  animation2.timeline = scrollTimeline;


  Demonstration:
  Demonstration:
http://output.jsbin.com/wiwode
  http://output.jsbin.com/wiwode
 
2) Duration of animation is infinite.
  var scrollTimeline = new ScrollTimeline(div, "horizontal", "20s");  // scroll range is mapped 0s - 20s.
  var animation1 = new Animation(new KeyframeEffect( { marginLeft: ['0px', '200px'] }, 10 * 1000), null);
  var animation2 = new Animation(new KeyframeEffect( { marginLeft: ['100px', '300px'] }, {duration:20 * 1000, iterations:Infinity}), null);
  animation1.timeline = scrollTimeline;
  animation2.timeline = scrollTimeline;
 
== Design (Gecko) ==
 
== Implement overview ==


== Problem of implementation. ==
== Problem of implementation. ==
1) The concept of time value
1) The concept of time value<br/>
We managed [https://w3c.github.io/web-animations/#time-value| time value] in Timeline, However ScrollTimeline doesn't have the concept of time. Because start position of ScrollTimeline is corresponding the start of animation. So ScrollTimeline doesn't have timve value but have relative position of animation.
We managed [https://w3c.github.io/web-animations/#time-value| time value] in Timeline, However ScrollTimeline doesn't have the concept of time. Because start position of ScrollTimeline is corresponding the start of animation. So ScrollTimeline doesn't have timve value but have relative position of animation.
In order to implement these, ScrollTimeline should have the start time of animation.
In order to implement these, ScrollTimeline should have the start time of animation.


2) Supporting multi ScrollTimeline
2) Supporting multi ScrollTimeline<br/>
The animation have same timeline object each other.
The animation have same timeline object each other.


3) End delay
3) End delay<br/>
ScrollTimeline has limited range. i.e. timeline is finite range.
ScrollTimeline has limited range. i.e. timeline is finite range.

Revision as of 06:59, 24 June 2016

** Note : This Document is WIP(Doesn't translate yet.) **

Scroll-driven animations.

For previous discussion, see Extended Timeline.

Introduction

Dean proposed the features of animation-trigger / animation-timebases / animation-behavior.
And, Brian/Botond proposed the Extended Timeline.
Thease ideas is similar to each idea. 特に、スクロール量とタイムラインの値をマッピングさせることについては非常に似ているため、お互いの仕様を共通化させることで、 CSS / Web Animation に適用したアーキテクチャを構築することが可能になります。 また、Firefox 49 から有効になった Bug 1178662「wrietable timeline」のバグで、タイムラインの設定 / 構築が容易に行えるようになったことから ScrollTimeline のようにスクロール量とマッピングされたタイムラインを作成することが可能になりました。

そのため、このドキュメントでは Web Animation / CSS Animation を考慮したスクロールベースのアニメーションについて記述しています。

Interface of script proposal

Same as DocumentTimeline, we should set ScrollTimeline to timeline property of animation.
Perhaps, WebIDL of ScrollTimeline is same to previous API proposal.

[Constructor ((Window or Element) scrollSource, Orientation orientation, optional DOMString maxTime)
interface ScrollTimeline : AnimationTimeline {
  attribute Orientation orientation;
  attribute DOMString maxTime;
};

// Is there an existing enum somewhere we can use for this?
enum Orientation { "vertical", "horizontal" };

コンストラクタの第3引数の maxTime は、アニメーションの繰り返し回数が無限(Infinte)の為に使用します。 この引数を指定しない場合は、以下の計算により自動で設定されます。

- もし ScrollTimeline に関連する Aniamtion が存在しない場合は 0ms
- Animation が存在する場合、target effect end
 - 値が Inifinity の場合、関連する Animation で一番大きな target effect end とする。
 - 関連するすべての Animation の target effect end が Infinity の場合、
   

Interface of CSS proposal

Usage of this API

1) Duration of animation is finite.

 var scrollTimeline = new ScrollTimeline(div, "vertical");
 var animation1 = new Animation(new KeyframeEffect( { marginLeft: ['0px', '200px'] }, 10000), null);
 var animation2 = new Animation(new KeyframeEffect( { marginLeft: ['100px', '300px'] }, 20000), null);
 animation1.timeline = scrollTimeline;
 animation2.timeline = scrollTimeline;
Demonstration:
 http://output.jsbin.com/wiwode

2) Duration of animation is infinite.

 var scrollTimeline = new ScrollTimeline(div, "horizontal", "20s");  // scroll range is mapped 0s - 20s.
 var animation1 = new Animation(new KeyframeEffect( { marginLeft: ['0px', '200px'] }, 10 * 1000), null);
 var animation2 = new Animation(new KeyframeEffect( { marginLeft: ['100px', '300px'] }, {duration:20 * 1000, iterations:Infinity}), null);
 animation1.timeline = scrollTimeline;
 animation2.timeline = scrollTimeline;

Design (Gecko)

Implement overview

Problem of implementation.

1) The concept of time value
We managed time value in Timeline, However ScrollTimeline doesn't have the concept of time. Because start position of ScrollTimeline is corresponding the start of animation. So ScrollTimeline doesn't have timve value but have relative position of animation. In order to implement these, ScrollTimeline should have the start time of animation.

2) Supporting multi ScrollTimeline
The animation have same timeline object each other.

3) End delay
ScrollTimeline has limited range. i.e. timeline is finite range.