PopStateEvent: hasUAVisualTransition 属性
hasUAVisualTransition
是 PopStateEvent
接口的一个只读属性,如果用户代理在分派此事件之前为这次导航执行了视觉过渡,则返回 true
,否则返回 false
。
当执行站点导航时,用户代理可能会提供内置的视觉过渡。如果站点作者也添加了视觉过渡,则用户代理和作者的过渡可能会冲突并让访问者感到困惑。该属性允许您检测是否提供了用户代理过渡,以便您可以跳过作者的过渡,从而获得更好的用户体验。
值
一个布尔值。
示例
js
window.addEventListener("popstate", async (event) => {
// Fetch the new content
const newContent = await fetchNewContent(location.href);
// 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-popstateevent-hasuavisualtransition |
浏览器兼容性
加载中…