Back to Svelte

04 Svelte Body

documentation/docs/05-special-elements/04-svelte-body.md

3.59.2552 B
Original Source
svelte
<svelte:body onevent={handler} />

Similarly to <svelte:window>, this element allows you to add listeners to events on document.body, such as mouseenter and mouseleave, which don't fire on window. It also lets you use actions on the <body> element.

As with <svelte:window> and <svelte:document>, this element may only appear at the top level of your component and must never be inside a block or element.

svelte
<svelte:body onmouseenter={handleMouseenter} onmouseleave={handleMouseleave} use:someAction />