Skip to content

Commit d992a18

Browse files
committed
Tidy up content progress use case
1 parent 287f6cd commit d992a18

3 files changed

Lines changed: 53 additions & 69 deletions

File tree

Overview.bs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -263,50 +263,49 @@ union.timeline = new ScrollTimeline({
263263

264264
### The content progress bar ### {#content-progress-bar-usecase}
265265

266-
There is much content that using to scroll linked animations.
267-
Here's one of these animation content, this content has a long article.
268-
And this content has a progress bar which indicates the current position of the article.
269-
270-
If we scroll the content, this progress bar increased / decreased.
266+
Another common example of an animation that tracks scroll position is a
267+
progress bar that is used to indicate the reader's position in a long
268+
article.
271269

272270
<figure>
273271
<img src="img/usecase3-2.svg" width="600"
274-
alt="Use case 3-2: Scroll based styling">
272+
alt="Use case: Scroll based styling">
275273
<figcaption>
276-
Use case 3-2: Content progress bar.<br>
277-
The left figure is before scroll, the progress bar is not displayed.<br>
278-
The right figure is after scroll, the progress bar advanced.
274+
Content progress bar.<br>
275+
The left figure shows the initial state before scrolling.<br>
276+
The right figure shows the progress bar is half-filled in since the
277+
user has scrolled half way through the article.
279278
</figcaption>
280279
</figure>
281280

282-
Usually, we won't need to this progress bar, because the scroll bar indicated the progress. But some content will want to hide the scroll bar, like this content.
281+
Typically, the scroll bar provides this visual indication but
282+
applications may wish to hide the scroll bar for aesthetic or useability
283+
reasons.
284+
285+
Using the 'animation-timeline' property, this example could be written
286+
as follows:
283287

284-
If we use animation-timeline, this example code will be as follow.
285288
<pre class='lang-css'>
286-
@keyframes progressAnimation {
287-
from {
288-
width: 0px;
289-
}
290-
to {
291-
width: 500px;
292-
}
289+
@keyframes progress {
290+
to { width: 100%; }
293291
}
294-
div#progress {
295-
width: 50%;
292+
#progress {
293+
width: 0px;
296294
height: 30px;
297295
background: red;
298-
animation: 1s linear progressAnimation;
299-
animation-trigger: scroll(element(#scrollableContainer), vertical);
296+
animation: progress 1s linear;
297+
animation-trigger: scroll(element(#body));
300298
animation-timeline: scroll();
301299
}
302300
</pre>
303301

304302
If we use this API for this case, the example code will be as follow:
303+
305304
<pre class='lang-javascript'>
306-
var animation = div.getAnimations()[0];
305+
var animation = div.animate({ width: '100%' }, 1000);
307306
animation.timeline = new ScrollTimeline(
308-
{ trigger: new ScrollTrigger({ scrollSource: scrollableElement,
309-
scrollOffset: '0px'}) });
307+
{ trigger: new ScrollTrigger({ scrollOffset: '0px' }) }
308+
);
310309
</pre>
311310

312311
## Combination scroll and time-base animations ## {#combination-scroll-and-time-base-animations-usecase}

img/usecase3-2.svg

Lines changed: 3 additions & 17 deletions
Loading

index.html

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -552,38 +552,36 @@ <h4 class="heading settled" data-level="2.3.1" id="scrollable-animation-usecase"
552552
<span class="p">}</span><span class="p">)</span><span class="p">;</span>
553553
</pre>
554554
<h4 class="heading settled" data-level="2.3.2" id="content-progress-bar-usecase"><span class="secno">2.3.2. </span><span class="content">The content progress bar</span><a class="self-link" href="#content-progress-bar-usecase"></a></h4>
555-
<p>There is much content that using to scroll linked animations.
556-
Here’s one of these animation content, this content has a long article.
557-
And this content has a progress bar which indicates the current position of the article.</p>
558-
<p>If we scroll the content, this progress bar increased / decreased.</p>
555+
<p>Another common example of an animation that tracks scroll position is a
556+
progress bar that is used to indicate the reader’s position in a long
557+
article.</p>
559558
<figure>
560-
<img alt="Use case 3-2: Scroll based styling" src="img/usecase3-2.svg" width="600">
561-
<figcaption> Use case 3-2: Content progress bar.<br> The left figure is before scroll, the progress bar is not displayed.<br> The right figure is after scroll, the progress bar advanced. </figcaption>
559+
<img alt="Use case: Scroll based styling" src="img/usecase3-2.svg" width="600">
560+
<figcaption> Content progress bar.<br> The left figure shows the initial state before scrolling.<br> The right figure shows the progress bar is half-filled in since the
561+
user has scrolled half way through the article. </figcaption>
562562
</figure>
563-
<p>Usually, we won’t need to this progress bar, because the scroll bar indicated the progress. But some content will want to hide the scroll bar, like this content.</p>
564-
<p>If we use animation-timeline, this example code will be as follow.</p>
565-
<pre class="lang-css highlight"><span class="n">@keyframes</span> progressAnimation <span class="p">{</span>
566-
<span class="nt">from </span><span class="p">{</span>
567-
<span class="k">width</span><span class="p">:</span> <span class="m">0</span><span class="l">px</span><span class="p">;</span>
568-
<span class="p">}</span>
569-
<span class="nt">to </span><span class="p">{</span>
570-
<span class="k">width</span><span class="p">:</span> <span class="m">500</span><span class="l">px</span><span class="p">;</span>
571-
<span class="p">}</span>
572-
<span class="p">}</span>
573-
<span class="nt">div#progress </span><span class="p">{</span>
574-
<span class="k">width</span><span class="p">:</span> <span class="m">5</span><span class="l">0</span>%;
563+
<p>Typically, the scroll bar provides this visual indication but
564+
applications may wish to hide the scroll bar for aesthetic or useability
565+
reasons.</p>
566+
<p>Using the <a class="property" data-link-type="propdesc" href="#propdef-animation-timeline" id="ref-for-propdef-animation-timeline-1">animation-timeline</a> property, this example could be written
567+
as follows:</p>
568+
<pre class="lang-css highlight"><span class="n">@keyframes</span> progress <span class="p">{</span>
569+
<span class="nt">to </span><span class="p">{</span> <span class="k">width</span><span class="p">:</span> <span class="m">10</span><span class="l">0</span>%; }
570+
}
571+
#progress {
572+
width: 0px;
575573
height: 30px;
576574
background: red;
577-
animation: 1s linear progressAnimation;
578-
animation-trigger: scroll(element(#scrollableContainer), vertical);
575+
animation: progress 1s linear;
576+
animation-trigger: scroll(element(#body));
579577
animation-timeline: scroll();
580578
}
581579
</pre>
582580
<p>If we use this API for this case, the example code will be as follow:</p>
583-
<pre class="lang-javascript highlight"><span class="kd">var</span> animation <span class="o">=</span> div<span class="p">.</span>getAnimations<span class="p">(</span><span class="p">)</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="p">;</span>
581+
<pre class="lang-javascript highlight"><span class="kd">var</span> animation <span class="o">=</span> div<span class="p">.</span>animate<span class="p">(</span><span class="p">{</span> width<span class="o">:</span> <span class="s1">'100%'</span> <span class="p">}</span><span class="p">,</span> <span class="mi">1000</span><span class="p">)</span><span class="p">;</span>
584582
animation<span class="p">.</span>timeline <span class="o">=</span> <span class="k">new</span> ScrollTimeline<span class="p">(</span>
585-
<span class="p">{</span> trigger<span class="o">:</span> <span class="k">new</span> ScrollTrigger<span class="p">(</span><span class="p">{</span> scrollSource<span class="o">:</span> scrollableElement<span class="p">,</span>
586-
scrollOffset<span class="o">:</span> <span class="s1">'0px'</span><span class="p">}</span><span class="p">)</span> <span class="p">}</span><span class="p">)</span><span class="p">;</span>
583+
<span class="p">{</span> trigger<span class="o">:</span> <span class="k">new</span> ScrollTrigger<span class="p">(</span><span class="p">{</span> scrollOffset<span class="o">:</span> <span class="s1">'0px'</span> <span class="p">}</span><span class="p">)</span> <span class="p">}</span>
584+
<span class="p">)</span><span class="p">;</span>
587585
</pre>
588586
<h3 class="heading settled" data-level="2.4" id="combination-scroll-and-time-base-animations-usecase"><span class="secno">2.4. </span><span class="content">Combination scroll and time-base animations</span><a class="self-link" href="#combination-scroll-and-time-base-animations-usecase"></a></h3>
589587
<h4 class="heading settled" data-level="2.4.1" id="movie-show-case-usecase"><span class="secno">2.4.1. </span><span class="content">The photo viewer</span><a class="self-link" href="#movie-show-case-usecase"></a></h4>
@@ -1092,9 +1090,9 @@ <h4 class="heading settled" data-level="4.1.2" id="current-time-algorithm"><span
10921090
<blockquote> <code>(<var>current scroll offset</var> - <code class="idl"><a data-link-type="idl" href="#dom-scrolltrigger-scrolloffset" id="ref-for-dom-scrolltrigger-scrolloffset-13">scrollOffset</a></code>) / (<code class="idl"><a data-link-type="idl" href="#dom-scrolltrigger-endscrolloffset" id="ref-for-dom-scrolltrigger-endscrolloffset-12">endScrollOffset</a></code> - <code class="idl"><a data-link-type="idl" href="#dom-scrolltrigger-scrolloffset" id="ref-for-dom-scrolltrigger-scrolloffset-14">scrollOffset</a></code>) × <a data-link-type="dfn" href="#effective-time-range" id="ref-for-effective-time-range-8">effective time range</a></code> </blockquote>
10931091
</ol>
10941092
</div>
1095-
<h3 class="heading settled" data-level="4.2" id="animation-timeline"><span class="secno">4.2. </span><span class="content">The <a class="property" data-link-type="propdesc" href="#propdef-animation-timeline" id="ref-for-propdef-animation-timeline-1">animation-timeline</a> property</span><a class="self-link" href="#animation-timeline"></a></h3>
1093+
<h3 class="heading settled" data-level="4.2" id="animation-timeline"><span class="secno">4.2. </span><span class="content">The <a class="property" data-link-type="propdesc" href="#propdef-animation-timeline" id="ref-for-propdef-animation-timeline-2">animation-timeline</a> property</span><a class="self-link" href="#animation-timeline"></a></h3>
10961094
<p>A <code class="idl"><a data-link-type="idl" href="#scrolltimeline" id="ref-for-scrolltimeline-8">ScrollTimeline</a></code> may be applied to a CSS Animation <a data-link-type="biblio" href="#biblio-css3-animations">[CSS3-ANIMATIONS]</a> using
1097-
the <a class="property" data-link-type="propdesc" href="#propdef-animation-timeline" id="ref-for-propdef-animation-timeline-2">animation-timeline</a> property.</p>
1095+
the <a class="property" data-link-type="propdesc" href="#propdef-animation-timeline" id="ref-for-propdef-animation-timeline-3">animation-timeline</a> property.</p>
10981096
<table class="def propdef" data-link-for-hint="animation-timeline">
10991097
<tbody>
11001098
<tr>
@@ -1129,7 +1127,7 @@ <h3 class="heading settled" data-level="4.2" id="animation-timeline"><span class
11291127
<td>no
11301128
</table>
11311129
<p><dfn class="dfn-paneled css" data-dfn-type="type" data-export="" id="typedef-single-animation-timeline">&lt;single-animation-timeline></dfn> = auto | scroll([<a class="production css" data-link-type="type" href="https://drafts.csswg.org/css-values-4/#time-value" title="Expands to: s | ms">&lt;time></a> [, <a class="production css" data-link-type="type" href="https://drafts.csswg.org/css-animations-1/#typedef-single-animation-fill-mode">&lt;single-animation-fill-mode></a>]])</p>
1132-
<p>The <a class="property" data-link-type="propdesc" href="#propdef-animation-timeline" id="ref-for-propdef-animation-timeline-3">animation-timeline</a> property is similar to properties like <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css-animations-1/#propdef-animation-duration">animation-duration</a> and <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css-animations-1/#propdef-animation-timing-function">animation-timing-function</a> in that it can have one or more values, each one imparting
1130+
<p>The <a class="property" data-link-type="propdesc" href="#propdef-animation-timeline" id="ref-for-propdef-animation-timeline-4">animation-timeline</a> property is similar to properties like <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css-animations-1/#propdef-animation-duration">animation-duration</a> and <a class="property" data-link-type="propdesc" href="https://drafts.csswg.org/css-animations-1/#propdef-animation-timing-function">animation-timing-function</a> in that it can have one or more values, each one imparting
11331131
additional behavior to a corresponding <a data-link-type="dfn" href="https://w3c.github.io/web-animations/#concept-animation">animation</a> on the
11341132
element, with the timelines matched up with animations as described <a href="https://drafts.csswg.org/css-animations-1/#animation-name">here</a>.</p>
11351133
<p>Each value has type <a class="production css" data-link-type="type" href="#typedef-single-animation-timeline" id="ref-for-typedef-single-animation-timeline-2">&lt;single-animation-timeline></a>, whose possible values have the
@@ -1932,7 +1930,8 @@ <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content
19321930
<aside class="dfn-panel" data-for="propdef-animation-timeline">
19331931
<b><a href="#propdef-animation-timeline">#propdef-animation-timeline</a></b><b>Referenced in:</b>
19341932
<ul>
1935-
<li><a href="#ref-for-propdef-animation-timeline-1">4.2. The animation-timeline property</a> <a href="#ref-for-propdef-animation-timeline-2">(2)</a> <a href="#ref-for-propdef-animation-timeline-3">(3)</a>
1933+
<li><a href="#ref-for-propdef-animation-timeline-1">2.3.2. The content progress bar</a>
1934+
<li><a href="#ref-for-propdef-animation-timeline-2">4.2. The animation-timeline property</a> <a href="#ref-for-propdef-animation-timeline-3">(2)</a> <a href="#ref-for-propdef-animation-timeline-4">(3)</a>
19361935
</ul>
19371936
</aside>
19381937
<aside class="dfn-panel" data-for="typedef-single-animation-timeline">

0 commit comments

Comments
 (0)