Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-view-transitions] Normalize the exposed transform for ::view-transition-group() pseudos to be Viewport-relative. #11456

Open
bramus opened this issue Jan 7, 2025 · 1 comment
Labels
css-view-transitions-1 View Transitions; Bugs only

Comments

@bramus
Copy link
Contributor

bramus commented Jan 7, 2025

When setting up a View Transition, all transforms are relative to the snapshot containing block origin.

Relevant spec snippets:

Set capture’s old transform to a that would map element’s border box from the snapshot containing block origin to its current visual position.

Set transform to a transform that would map newRect from the snapshot containing block origin to its current visual position.

These transforms are then used in the ::view-transition-group’s keyframes (setting the starting position) and on the element itself (setting its ending position).

For example, when animating a position: fixed element in a browser that has a retractable top bar of 56px high, a top,left translation from 100,100 to 24,24 of that element results in the following transforms:

  • from transform: matrix(1, 0, 0, 1, 100, 156)
  • to transform: matrix(1, 0, 0, 1, 24, 80)

See this screenshot taken in Chrome on Android: the box got animated from position 24,24 as measured against the viewport (red outline + red arrow) but ends up being 24,80 when measured against the snapshot containing block (blue outline + blue arrow)

vt-snapshot-containing-block


When getting the keyframes of the resulting ::view-transition-group pseudo using animation.effect.getKeyframes() you end up with the following (simplified):

[
  {
    computedOffset: 0,
    transform: "matrix(1, 0, 0, 1, 100, 156)"
  },
  {
    computedOffset: 1,
    transform: "matrix(1, 0, 0, 1, 24, 80)"
  }
]

From an author POV these values are problematic, because the transforms contain values that are not relative to the coordinate space authors have access to, namely the (layout) viewport:

  • Extracting the start and end positions from these keyframes yields values that are off by <height-of-the-retractable-top-bar>
  • Doing something like animation.effect.setKeyframes(animation.effect.getKeyframes()) is destructive because the element has now shifted by <height-of-the-retractable-top-bar>.

To fix this issue I suggest that engines keep on using the snapshot containing block-relative offsets internally, but expose viewport-relative offsets to authors. The viewport as presented at the time of the new state would be used for this.

That way authors can rely on the keyframes for extracting the correct positional information and manipulate the generated keyframes without needing to worry about messing up the positions.

@bramus bramus added the css-view-transitions-1 View Transitions; Bugs only label Jan 7, 2025
@bramus
Copy link
Contributor Author

bramus commented Jan 7, 2025

/ping @noamr @vmpstr @nt1m for input
/fyi @mattgperry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css-view-transitions-1 View Transitions; Bugs only
Projects
None yet
Development

No branches or pull requests

1 participant