diff --git a/src/components/IframeDrawer.vue b/src/components/IframeDrawer.vue index 70428af6..bf18b57f 100644 --- a/src/components/IframeDrawer.vue +++ b/src/components/IframeDrawer.vue @@ -21,11 +21,23 @@ const headerShow = ref(false) const iframeRef = ref(null) const currentUrl = ref(props.url) const delayCloseTimer = ref(null) +const removeTopBarClassInjected = ref(false) useEventListener(window, 'popstate', updateIframeUrl) nextTick(() => { useEventListener(iframeRef.value?.contentWindow, 'historyChange', updateCurrentUrl) useEventListener(iframeRef.value?.contentWindow, 'popstate', updateCurrentUrl) + + useEventListener(iframeRef.value?.contentWindow, 'DOMContentLoaded', () => { + if (headerShow.value) { + iframeRef.value?.contentWindow?.document.documentElement.classList.add('remove-bili-top-bar-without-placeholder') + removeTopBarClassInjected.value = true + } + else { + iframeRef.value?.contentWindow?.document.documentElement.classList.remove('remove-bili-top-bar-without-placeholder') + removeTopBarClassInjected.value = false + } + }) }) onMounted(() => { @@ -238,11 +250,12 @@ watchEffect(() => { ref="iframeRef" :src="props.url" :style="{ - bottom: headerShow ? `var(--bew-top-bar-height)` : '0', + // Prevent top bar shaking when before the remove-bili-top-bar-without-placeholder class is injected + top: !removeTopBarClassInjected ? `calc(-1 * var(--bew-top-bar-height))` : '0', }" frameborder="0" pointer-events-auto - pos="absolute left-0" + pos="relative left-0" w-full h-full /> diff --git a/src/components/IframePage.vue b/src/components/IframePage.vue index b79c4ebb..ac41ec67 100644 --- a/src/components/IframePage.vue +++ b/src/components/IframePage.vue @@ -59,7 +59,7 @@ defineExpose({