Skip to content

Conversation

@dnlzro
Copy link

@dnlzro dnlzro commented Aug 29, 2025

Problem

This polyfill applies scroll-driven animations even when the scroll container has no overflow (i.e., when clientHeight === scrollHeight). According to the specification (source):

Progress (the current time) for a scroll progress timeline is calculated as: scroll offset ÷ (scrollable overflow sizescroll container size)

If the 0% position and 100% position coincide (i.e. the denominator in the current time formula is zero), the timeline is inactive.

When there is no overflow, then scrollable overflow sizescroll container size = 0. Currently, the timeline is set to 100% or NaN in these cases. Instead, it should be set to inactive.

Changes

  1. ScrollTimeline.currentTime: Return unresolved when maxScrollPos <= 0.
  2. ViewTimeline.currentTime: Return unresolved when offsets.end === offsets.start.

Note: When the currentTime method returns unresolved (i.e., null), the tickAnimation function will cancel the animation. This ensures no effects are applied when the timeline is inactive.

Note: I think these changes also indirectly address the first issue raised in #298.

@boneyfantaseas
Copy link

Instantly no annoying "Animation.currentTime" errors anymore, lovely. I use it for a scrollbar indicator approach and I learned that it works this solution works with indicators as pseudo elements but not as real DOM nodes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants