diff --git a/preview/src/blocks/GlyphsTable/GlyphsTable.svelte b/preview/src/blocks/GlyphsTable/GlyphsTable.svelte index f6507cb4..c58aedaa 100644 --- a/preview/src/blocks/GlyphsTable/GlyphsTable.svelte +++ b/preview/src/blocks/GlyphsTable/GlyphsTable.svelte @@ -13,21 +13,13 @@ let fontSize = 70 let hovered = false + let scrolled = false let leaveTimeout: number $: height = fontSize + 30 $: width = height * 1.3 - onMount(() => { - const requests = VARIANTS.map(v => load(`./ttf/Lilex-${v}.ttf`)) - Promise.all(requests) - .then(masters => { - fonts.push(...masters) - loading = false - }) - }) - function handleHover () { hovered = true if (leaveTimeout) { @@ -41,6 +33,29 @@ }, 500) } + function handleScroll () { + if (!scrolled) { + scrolled = true + setTimeout(() => { + scrolled = false + }, 300) + } + } + + onMount(() => { + const requests = VARIANTS.map(v => load(`./ttf/Lilex-${v}.ttf`)) + Promise.all(requests) + .then(masters => { + fonts.push(...masters) + loading = false + }) + + document.addEventListener('scroll', handleScroll) + return () => { + document.removeEventListener('scroll', handleScroll) + } + }) + $: glyphs = loading || !(selectedVariant in fonts) ? [] : renderGlyphs(fonts[selectedVariant]) @@ -67,7 +82,7 @@ style:--glyph-width="{width}px" style:--glyph-height="{height}px" class="glyphs" - class:hover={hovered}> + class:hover={!scrolled && hovered}> {#each glyphs as glyph}