@ -963,20 +963,22 @@ A custom transition function can also return a `tick` function, which is called
< script >
export let visible = false;
function typewriter(node, { speed = 50 }) {
function typewriter(node, { speed = 1 }) {
const valid = (
node.childNodes.length === 1 & &
node.childNodes[0].nodeType === Node.TEXT_NODE
);
if (!valid) return {};
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 ;
const duration = text.length / (speed * 0.01) ;
return {
duration,
tick: ( t, u) => {
tick: t => {
const i = ~~(text.length * t);
node.textContent = text.slice(0, i);
}
@ -985,7 +987,7 @@ A custom transition function can also return a `tick` function, which is called
< / script >
{#if visible}
< p in:typewriter = "{{ speed: 20 }}">
< p in:typewriter = "{{ speed: 1 }}">
The quick brown fox jumps over the lazy dog
< / p >
{/if}