Skip to content

Commit

Permalink
Allow self keyword as the source type (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
bramus authored Jan 19, 2024
1 parent 147d187 commit db93642
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
26 changes: 23 additions & 3 deletions demo/basic/anonymous-scroll-timeline-animation-shorthand.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,30 @@
to { width: 120px; }
}

@keyframes outlineChange {
from { outline: 0px solid lime; }
to { outline: 10px solid lime; }
}

#box_one {
width: 100px;
height: 100px;
background-color: green;
animation: linear colorChange both, linear widthChange both, move linear;
animation-timeline: scroll(root), auto, scroll(nearest y);
overflow-y: scroll;
animation:
linear colorChange both,
linear widthChange both,
move linear,
linear outlineChange both;
animation-timeline:
scroll(root),
auto,
scroll(nearest y),
scroll(self y);
}

.content {
height: 400px;
}

.spacer {
Expand All @@ -44,7 +62,9 @@
<body>

<div id="container">
<div id="box_one"></div>
<div id="box_one">
<div class="content"></div>
</div>
<div class="spacer"></div>
</div>

Expand Down
11 changes: 10 additions & 1 deletion src/scroll-timeline-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,16 @@ function findClosestAncestor(element, matcher) {
}

export function getAnonymousSourceElement(sourceType, node) {
return sourceType == 'root' ? document.scrollingElement : getScrollParent(node);
switch (sourceType) {
case 'root':
return document.scrollingElement;
case 'nearest':
return getScrollParent(node);
case 'self':
return node;
default:
throw new TypeError('Invalid ScrollTimeline Source Type.');
}
}

function isBlockContainer(element) {
Expand Down
2 changes: 1 addition & 1 deletion src/scroll-timeline-css-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const ANIMATION_KEYWORDS = [
];

const TIMELINE_AXIS_TYPES = ['block', 'inline', 'x', 'y'];
const ANONYMOUS_TIMELINE_SOURCE_TYPES = ['nearest', 'root'];
const ANONYMOUS_TIMELINE_SOURCE_TYPES = ['nearest', 'root', 'self'];

// Parse a styleSheet to extract the relevant elements needed for
// scroll-driven animations.
Expand Down

0 comments on commit db93642

Please sign in to comment.