switch to a simpler css based typing animation

Signed-off-by: ngn <ngn@ngn.tf>
This commit is contained in:
ngn
2025-07-24 15:40:38 +03:00
parent 53a0fc3927
commit ee4b8a1d50
2 changed files with 20 additions and 68 deletions

View File

@@ -1,77 +1,27 @@
<script> <script>
import { onMount } from "svelte";
import { browser } from "$app/environment";
import { _ } from "$lib/locale.js"; import { _ } from "$lib/locale.js";
let { picture, title } = $props();
export let picture = "";
export let title = "";
let title_cur = title;
let javascript = false;
// TODO: make the animation first delete and then type
// do the typing animation
function animate(title) {
// animation is displayed in the browser obv
if (!browser) {
return;
}
// clear any previous timeouts
let id = window.setTimeout(function () {}, 0);
while (id--) {
clearTimeout(id);
}
// reset the current title and add each letter with a timeout to give the
// epic typing effect
title_cur = "";
for (let i = 0; i < title.length; i++) {
setTimeout(() => {
title_cur += title[i];
}, i * 70);
}
}
onMount(() => {
javascript = true;
});
$: animate(title);
</script> </script>
<header> <header>
<div> <div style="--length: {title.length + 1}">
{#if javascript} <h1>{title}<span>_</span></h1>
<h1 class="title">{title_cur}</h1>
<h1 class="cursor">_</h1>
{:else}
<h1 class="title">{title}</h1>
{/if}
</div> </div>
<img src="/assets/{picture}.png" alt="" /> <img src="/assets/{picture}.png" alt="" />
</header> </header>
<style> <style>
header { header {
background: var(--transparent);
width: 100%;
height: 100%;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
align-items: end; align-items: end;
background: var(--transparent);
} }
header div { header div {
display: flex; padding: 100px 40px 10px 40px;
flex-direction: row; color: var(--color);
align-items: end;
padding: 40px 40px 10px 40px;
font-size: var(--size-6); font-size: var(--size-6);
font-family: font-family:
Consolas, Consolas,
@@ -83,20 +33,16 @@
Courier New, Courier New,
monospace; monospace;
white-space: nowrap; white-space: nowrap;
justify-content: start;
width: min-content;
} }
header h1 { header div h1 {
color: var(--color);
}
header div .title {
text-shadow: var(--text-shadow); text-shadow: var(--text-shadow);
overflow: hidden; overflow: hidden;
white-space: nowrap;
animation: typing 0.8s steps(var(--length), end);
} }
header div .cursor { header div span {
content: "_"; content: "_";
display: inline-block; display: inline-block;
animation: blink 1.5s steps(2) infinite; animation: blink 1.5s steps(2) infinite;
@@ -108,10 +54,6 @@
} }
@media only screen and (max-width: 900px) { @media only screen and (max-width: 900px) {
header {
display: block;
}
header img { header img {
display: none; display: none;
} }

View File

@@ -53,6 +53,16 @@
} }
} }
/* typing animation */
@keyframes typing {
from {
width: 0;
}
to {
width: 100%;
}
}
* { * {
padding: 0; padding: 0;
margin: 0; margin: 0;