-
Notifications
You must be signed in to change notification settings - Fork 1
/
splitting-by-line.js
55 lines (43 loc) · 1.25 KB
/
splitting-by-line.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
function splittingByLine() {
const elAllSplitting = document.querySelectorAll('[data-splitting]')
let elWords
let elChars
let line = 0
let linechar = 0
let linechartotal = 0
var linecharmax = 0
elAllSplitting.forEach((txt) => {
line = 0
linechar = 0
elWords = txt.querySelectorAll('.word.words')
for (let w = 0; w < elWords.length; w++) {
if (line !== Number(elWords[w].style.getPropertyValue("--line-index"))) {
line++
linechar = 0
}
if (!linechar) {
linechartotal = document.querySelectorAll(`.word.words[style*="--line-index:${line}"] .char`).length
}
elChars = elWords[w].querySelectorAll('.char')
for (let c = 0; c < elChars.length; c++) {
elChars[c].style.setProperty("--linechar-index", linechar)
elChars[c].style.setProperty("--line-index", line)
elChars[c].style.setProperty("--linechar-total", linechartotal)
elChars[c].classList.add("sbl")
linechar++
if (linechartotal > linecharmax) {
linecharmax = linechartotal
}
}
}
txt.style.setProperty("--linechar-max", linecharmax)
})
elAllSplitting.forEach((txt) => {
txt.classList.add("sbl1");
})
setTimeout(() => {
elAllSplitting.forEach((txt) => {
txt.classList.add("sbl2");
})
}, 500)
}