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

High level options for customizing animation for offscreen elements #84

Closed
vmpstr opened this issue Nov 16, 2021 · 11 comments
Closed

High level options for customizing animation for offscreen elements #84

vmpstr opened this issue Nov 16, 2021 · 11 comments

Comments

@vmpstr
Copy link
Collaborator

vmpstr commented Nov 16, 2021

From the explainer:

Open question: Default animations work well for things which are at least partially in-viewport in both Page-A and Page-B, but it gets tricky if you consider a non-sticky header that scrolled out of view by 1000s of pixels.

@jakearchibald
Copy link
Collaborator

I don't have a good idea for this aside from another CSS property:

.whatever {
  page-transition-clamp-position: just-out-of-viewport-please;
}

@jakearchibald
Copy link
Collaborator

@jakearchibald
Copy link
Collaborator

A high level solution here would be something like:

.whatever {
  page-transition-offscreen-behavior: …;
}

Where the values could be:

  • default - element takes its true position (the current behaviour).
  • clamp - clamp the element's position so it's just out of view, compared to the other end of the animation.
  • absent - behave as if the element is absent in this half of the transition.

But I'm going to look into lower-level solutions.

@absurdprofit
Copy link

@jakearchibald why not leave it up to the user since they have to offer up the shared elements anyways?

@jakearchibald
Copy link
Collaborator

I think you're talking about the low-level solution 😄

It might not be as easy as you think. Try writing some demo code for it.

@absurdprofit
Copy link

Yea you're right. The idea would be library authors would need to orchestrate these transitions and this could be left to them. I will try a demo though.

@khushalsagar khushalsagar changed the title Default animations of far-away elements High level options for customizing animation for offscreen elements Aug 16, 2022
@khushalsagar
Copy link
Collaborator

The default behaviour is that the element animates from its actual viewport position. #117 is exploring the low level solution to give devs the computed info so the exact behaviour can be expressed in script. I'll leave this one open for a high level CSS attribute to do the common options.

@jakearchibald
Copy link
Collaborator

I don't think we need the clamp option initially, but I think we should ship something to do absent along with MPA transitions (which will typically use less JS).

@khushalsagar
Copy link
Collaborator

+1 to Jake's comment, we can start with a simpler property for now. So the summarized proposal is:

  • Add a new CSS property view-transition-offscreen which customizes the behavior for named elements based on their position in the snapshot viewport.
  • The property has 2 values: auto and absent. auto indicates that the UA should render the element irrespective of its viewport position (as-if its onscreen). Would be nice to allow flexibility to the UA to optimize out such elements in case the transition is on memory constrained devices. That's why "should" instead of "must".
  • absent indicates that if the element's ink overflow rectangle does not intersect the snapshot viewport, the element does not participate in the transition (as-if its view-transition-name's computed value was none).
  • The computation for the element's viewport position for the decision above can be done here for old elements. And here for new elements. The subtlety is that for new elements we do it before resolving the ready promise so script can observe the final pseudo DOM structure.

@jakearchibald
Copy link
Collaborator

  • auto indicates that the UA should render the element irrespective of its viewport position (as-if its onscreen). Would be nice to allow flexibility to the UA to optimize out such elements in case the transition is on memory constrained devices. That's why "should" instead of "must".

Hmmmmm, it might not be compatible to discard elements in some later release without an opt-in. However, auto seems like good wording, since it covers the content-visibility case.

+1 to the rest.

@khushalsagar
Copy link
Collaborator

Closing this so we can continue the discussion in csswg.

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

No branches or pull requests

4 participants