Skip to content

[css-view-transitions-2] Retaining view-transition-class (and view-transition-group) from old state #10757

@noamr

Description

@noamr

When resolving view-transition-class, the rule is "last capture wins". That means that as long a view-transition has a new state, the old class is discarded.

However, there are legit use-cases for retaining the "old" class without having to explicitly specifying it again.
For example, if the author uses an ordinary class in-viewport to ascertain that a certain element intersects with the viewport, they should be able to use the following to customize the animation:

.element.in-viewport {
  view-transition-class: fly;
}

.element:not(.in-viewport) {
  view-transition-class: fade;
}

With the current "last capture wins" rule, the fade-only rule would only apply when the element flys out, and it's impossible to use view-transition-class to make it fade also when flying in, because .in-viewport would be true in the new state.

Proposing to have a function that applies to view-transition-class, and can be applied to view-transition-group if we use the same rule in #10631, that copies the value from the old state.

e.g.:

view-transition-class: from-old() new-class-1 new-class2;

There is probably a better name for this, but the general idea is that a particular function "copies over" the names from the old state, and that this is specific to view-transitions rather than a generic merge primitive.

/cc @khushalsagar @vmpstr @nt1m @fantasai

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions