old-website/static/js/title.js
Michał 0ddc2a20b2 Add darkmode
Prettier titles
2023-07-21 13:25:33 +01:00

32 lines
742 B
JavaScript

const title = document.querySelector('h1');
const titleHeight = title.offsetHeight;
let titleText = title.textContent;
let letterOffset = 0;
let timeOffset = 10;
title.textContent = '';
title.style.height = titleHeight + 'px';
title.style.opacity = "1";
titleText.split('').forEach((letter) => {
let span = document.createElement('span');
span.textContent = letter;
span.style.left = letterOffset + 'px';
span.style.transform = 'translateY(100%)';
title.append(span);
setTimeout(() => {
span.style.transform = '';
}, timeOffset);
letterOffset += span.offsetWidth;
timeOffset += 100;
});
setTimeout(() => {
title.textContent = '';
title.textContent = titleText;
}, timeOffset + 500);