<svelte:window>, this element allows you to add listeners to events on document, such as visibilitychange, which don’t fire on window. It also lets you use attachments on document.
As with
<svelte:window>, this element may only appear at the top level of your component and must never be inside a block or element.Event Listeners
You can add any valid document event listener:Common document events
onvisibilitychange- Document visibility changesonfullscreenchange- Fullscreen mode changesonpointerlockchange- Pointer lock state changesonselectionchange- Text selection changesonkeydown- Key is pressed (anywhere in document)onkeyup- Key is releasedonclick- Click anywhere in document
Bindings
You can bind to the following document properties (all are readonly):Element
The element that currently has focus.
Element | null
The element currently displayed in fullscreen mode, or
null if no element is in fullscreen.Element | null
The element that currently has the pointer locked, or
null if pointer is not locked.string
The visibility state of the document. Possible values:
"visible", "hidden".