Skip to main content
Create new
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
<script>
let visible = $state(false);

function typewriter(node, { speed = 1 }) {
const valid = node.childNodes.length === 1 && node.childNodes[0].nodeType === Node.TEXT_NODE;

if (!valid) {
throw new Error(`This transition only works on elements with a single text node child`);
}

const text = node.textContent;
const duration = text.length / (speed * 0.01);

return {
duration,
tick: (t) => {
const i = ~~(text.length * t);
node.textContent = text.slice(0, i);
}
};
}
</script>

<label>
<input type="checkbox" bind:checked={visible} />
visible
</label>

{#if visible}
<p transition:typewriter>The quick brown fox jumps over the lazy dog</p>
{/if}

loading Svelte compiler...
/* Select a component to see its compiled code */
result = svelte.compile(source, {
generate: ,
});
/* Select a component to see its compiled code */