8000 [css-view-transitions-2] Script event on old Document for cross-document ViewTransitions · Issue #8785 · w3c/csswg-drafts · GitHub
[go: up one dir, main page]

Skip to content

[css-view-transitions-2] Script event on old Document for cross-document ViewTransitions #8785

@khushalsagar

Description

@khushalsagar

View Transition API needs to provide an event on the old Document to enable customization of the transition based on the URL for the new Document and the current Document state. For example, the Document could have changed from user interaction after its first load.

The proposed IDL is as follows:

[Exposed=Window]
interface ViewTransitionBeforeCaptureEvent : Event {
  // The URL being navigated to, after resolving server-side redirects.
  readonly attribute USVString url;

  // Opaque contextual information passed to the new Document.
  // This must be a serializable object : https://developer.mozilla.org/en-US/docs/Glossary/Serializable_object.
  attribute any context;
};

The following is sample code using this event:

document.addEventListener("viewtransitionbeforecapture", (event) => {
  // Cancel the transition (based on new URL) if needed.
  if (shouldNotTransition(event.toURL)) {
    event.preventDefault();
    return;
  }

  // Set up names on elements based on the new URL.
  if (shouldTagThumbnail(event.toURL)) {
    thumbnail.style.viewTransitionName = "full-embed";
  }

  // Add opaque contextual information to share with the new Document.
  event.context = createTransitionContext(event.url);
});

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

      0