Skip to content

Commit c4e6fd2

Browse files
committed
[scroll-animations] Add threshold definition to element-based offset
1 parent 5a49df2 commit c4e6fd2

File tree

3 files changed

+168
-36
lines changed

3 files changed

+168
-36
lines changed

scroll-animations-1/Overview.bs

+44-11
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ enum Edge { "start", "end" };
497497
dictionary ElementBasedOffset {
498498
Element target;
499499
Edge edge = "start";
500+
double threshold = 0.0;
500501
};
501502
</pre>
502503

@@ -505,17 +506,18 @@ dictionary ElementBasedOffset {
505506

506507
: <dfn dict-member for=ElementBasedOffset>target</dfn>
507508
:: The target whose intersection with {{source}}'s [=scrolling box=] determines
508-
the concrete scroll offset.
509+
the concrete scroll offset.
509510

510511
: <dfn dict-member for=ElementBasedOffset>edge</dfn>
511-
:: The edge of {{source}}'s [=scrolling box=] which the target should
512-
intersect with.
513-
514-
</div>
512+
:: The edge of {{source}}'s [=scrolling box=] in the direction specified by
513+
the {{orientation}} which the target should intersect with.
515514

515+
: <dfn dict-member for=ElementBasedOffset>threshold</dfn>
516+
:: A double in the range of [0.0, 1.0] that represent the precentage
517+
of the target that is expected to be visible in {{source}}'s [=scrollport=]
518+
at the intersection offset.
516519

517-
Issue: TODO: Add threshold value that allows authors to control how much of the
518-
target should become visible within scrollport.
520+
</div>
519521

520522

521523
The procedure to <dfn>resolve a element-based offset</dfn> given
@@ -550,17 +552,48 @@ The procedure to <dfn>resolve a element-based offset</dfn> given
550552
with the <var>target box</var>'s start edge in the axis and direction
551553
determined by {{orientation}}.
552554

555+
1. Let <var>threshold amount</var> be the result of evaluating the following
556+
expression where <var>target dimension</var> is <var>target box</var>'s dimension in the axis
557+
determined by {{orientation}}.
558+
<blockquote>
559+
<code><var>threshold amount</var> = {{threshold}} &times; <var>target dimension</var></code>
560+
</blockquote>
561+
562+
563+
1. Adjust <var>scroll offset</var> by <var>threshold amount</var> as follow:
564+
<div class="switch">
565+
566+
: If <var>offset</var>'s {{edge}} is 'start',
567+
:: <var>scroll offset</var> = <var>scroll offset</var> - <var>threshold amount</var>.
568+
569+
: Otherwise (<var>offset</var>'s {{edge}} is 'end'),
570+
:: <var>scroll offset</var> = <var>scroll offset</var> + <var>threshold amount</var>.
571+
572+
</div>
573+
553574
1. Clamp the value of <var>scroll offset</var> to be within the {{source}}'s
554575
scroll range.
555576

556577
1. The [=effective scroll offset=] is <var>scroll offset</var>
557578

558579

580+
<div class="note">
581+
Note: With threshold 0.0, the algorithm selects the effective scroll offset such
582+
that the target is adjacent to the [=scrollport=] at the given edge but not yet
583+
visible. The upcoming threshold value will allow authors to control the amount
584+
of target that needs to be visible in [=scrollport=]. In particular threshold
585+
value 1.0 ensure that target is fully visible (as long as [=scrollport=] is
586+
large enough).
587+
588+
<figure>
589+
<img src="img/example-element-based-threshold.svg" width="600"
590+
alt="Example usage of element-based offset.">
591+
<figcaption>
592+
Threshold controls how much of target should be visible in [=scrollport=].
593+
</figcaption>
594+
</figure>
559595

560-
Note: The current algorithm selects the effective scroll offset such that the
561-
target is adjacent to the scrollport but not yet visible. The upcoming threshold
562-
value will allow authors to control the amount of target that needs to be
563-
visible.
596+
</div>
564597

565598
<div class="example">
566599
Here is a basic example showing how element-based offsets can be used to declare
Loading

scroll-animations-1/img/example-element-based.svg

+25-25
Loading

0 commit comments

Comments
 (0)