-
Notifications
You must be signed in to change notification settings - Fork 0
/
color.js
41 lines (33 loc) · 1.25 KB
/
color.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
// Decoration for headings
export default function decorate() {
document.addEventListener('DOMContentLoaded', () => {
const heading = document.querySelector('.title');
const text = heading.innerText;
const letters = text.split('');
const colors = ['red', 'green', 'blue', 'orange', 'purple', 'pink'];
const coloredText = letters.map((letter, index) => {
const span = document.createElement('span');
span.style.color = colors[index % colors.length];
span.innerText = letter;
return span;
})
let currentIndex = 0;
let intervalId = null;
function strobeEffect() {
intervalId = setInterval(() => {
const spans = heading.querySelectorAll('span');
spans.forEach((span) => {
span.style.opacity = '0.8';
});
const currentSpan = spans[currentIndex % spans.length];
currentSpan.style.opacity = '1';
currentIndex++;
}, 1000)
}
heading.innerHTML = '';
coloredText.forEach((span) => {
heading.appendChild(span);
})
strobeEffect();
})
}