NavigateEvent:hasUAVisualTransition 屬性

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

實驗性: 這是一項實驗性技術
在生產中使用此技術之前,請仔細檢查瀏覽器相容性表格

NavigateEvent 介面的只讀屬性 hasUAVisualTransition 返回一個布林值,如果使用者代理在此事件分發之前為此導航執行了視覺過渡,則返回 true,否則返回 false

使用者代理可以在執行站點導航時提供內建的視覺過渡。如果站點作者也添加了視覺過渡,使用者代理和作者的過渡可能會發生衝突,令訪問者感到困惑。此屬性允許您檢測是否提供了使用者代理過渡,以便您可以跳過作者過渡,從而獲得更好的使用者體驗。

一個布林值。

示例

js
navigation.addEventListener("navigate", (event) => {
  // Some navigations, e.g. cross-origin navigations, we
  // cannot intercept. Let the browser handle those normally.
  if (!event.canIntercept) {
    return;
  }

  // Don't intercept fragment navigations or downloads.
  if (event.hashChange || event.downloadRequest !== null) {
    return;
  }

  event.intercept({
    handler() {
      // Fetch the new content
      const newContent = await fetchNewContent(event.destination.url, {
        signal: event.signal,
      });

      // The UA does not support View Transitions, or the UA
      // already provided a Visual Transition by itself (e.g. swipe back).
      // In either case, update the DOM directly
      if (!document.startViewTransition || event.hasUAVisualTransition) {
        doSinglePageAppNav(newContent);
        return;
      }

      // Update the content using a View Transition
      document.startViewTransition(() => {
        doSinglePageAppNav(newContent);
      });
    },
  });
});

規範

規範
HTML
# dom-navigateevent-hasuavisualtransition

瀏覽器相容性

另見