-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
27 lines (23 loc) · 834 Bytes
/
main.js
File metadata and controls
27 lines (23 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// title content get saved and deleted, for later animation
const title = document.getElementById("title");
const text = title.innerHTML;
title.innerHTML = null;
// buffer element with the same dith as the former title
const buffer = document.getElementById("buffer");
buffer.style.width = text.length + "ch";
// buffer.innerHTML = text;
let index = 0;
function typeEffect()
{
if (index < text.length)
{
// Inster char after char into title element
title.innerHTML += text.charAt(index);
// Decrease width of buffer, cause the title element gets bigger
buffer.style.width = (text.length - (index + 1)) + "ch";
// buffer.innerHTML = text.substring(index + 1, text.length);
index++;
setTimeout(typeEffect, Math.random() * 50 + 25);
}
}
setTimeout(typeEffect, 500);