Examples
- Introduction
- Reactivity
- Props
- Logic
- Events
- Bindings
- Lifecycle
- Stores
- Motion
- Transitions
- Animations
- Easing
- SVG
- Actions
- Classes
- Component composition
- Context API
- Special elements
- Module context
- Debugging
- 7GUIs
- Miscellaneous
App.svelte
click_outside.js
<script> import { clickOutside } from "./click_outside.js"; let showModal = true; </script> <button on:click={() => (showModal = true)}>Show Modal</button> {#if showModal} <div class="box" use:clickOutside on:outclick={() => (showModal = false)}> Click outside me! </div> {/if} <style> .box { --width: 100px; --height: 100px; position: absolute; width: var(--width); height: var(--height); left: calc(50% - var(--width) / 2); top: calc(50% - var(--height) / 2); display: flex; align-items: center; padding: 8px; border-radius: 4px; background-color: #ff3e00; color: #fff; text-align: center; font-weight: bold; } </style>
loading editor...
Console
loading Svelte compiler...
loading editor...
Compiler options
result = svelte.compile(source, {
generate:
});loading editor...