-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
60 lines (43 loc) · 1.42 KB
/
script.js
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
const splitText = (txt) => {
const letters = txt.innerText.split('')
txt.innerText = ''
letters.forEach(el => {
const span = document.createElement('span')
span.classList.add('letter')
span.innerText = el
txt.appendChild(span)
});
}
const splitWords = (txt) => {
const words = txt.innerText.split(/(\s+)/);
txt.innerText = ''
words.forEach(el => {
const span = document.createElement('span')
span.classList.add('word')
span.innerText = el
txt.appendChild(span)
});
}
window.addEventListener('DOMContentLoaded', () => {
const heading_one = document.querySelector('h1')
const heading_two = document.querySelector('h2')
splitText(heading_one)
splitWords(heading_two)
const letters = heading_one.querySelectorAll('.letter')
const words = heading_two.querySelectorAll('.word')
setTimeout(() => {
heading_one.style.opacity = 1
letters.forEach((el, i) => {
el.style.setProperty("--animation-delay", `${ i * (0.6 / letters.length)}s`);
el.classList.add('enter')
})
letters[letters.length - 1].addEventListener('transitionend', () => {
heading_two.style.opacity = 1
words.forEach((el, i) => {
el.style.setProperty("--animation-delay", `${ i * (0.6 / words.length)}s`);
el.classList.add('scaleIn')
})
})
}, 500)
})