Skip to content

Commit

Permalink
fix(fullscreen videos): scroll to element after exiting fullscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Mar 1, 2024
1 parent 5cceaba commit 5e4c38a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup>
import { useEventListener } from '@vueuse/core'
import { toast, Toaster } from 'vue-sonner'
useAppStatistics()
Expand All @@ -20,6 +21,30 @@
toast.error(error.message)
})
// Restore scroll position after fullscreen
useEventListener('fullscreenchange', async (event) => {
const isInFullscreen = document.fullscreenElement !== null
if (isInFullscreen) {
return
}
await nextTick()
await new Promise((resolve) => setTimeout(resolve, 50))
requestAnimationFrame(() => {
requestAnimationFrame(() => {
event.target.scrollIntoView({
block: 'center',
inline: 'center',
})
})
})
})
console.info(
'%cWe ❤︎ open source!',
'font-size:32px;font-weight:bold;letter-spacing:0.02em;color:hsl(205, 78%, 62%);background-color:white;padding:8px 16px;'
Expand Down

0 comments on commit 5e4c38a

Please sign in to comment.