MCPcopy Create free account
hub / github.com/codrops/TypeShuffleAnimation / constructor

Method constructor

src/js/typeShuffle.js:98–133  ·  view source on GitHub ↗

* Constructor. * @param {Element} DOM_el - main text element

(DOM_el)

Source from the content-addressed store, hash-verified

96 * @param {Element} DOM_el - main text element
97 */
98 constructor(DOM_el) {
99 this.DOM.el = DOM_el;
100 // Apply Splitting (two times to have lines, words and chars)
101 const results = Splitting({
102 target: this.DOM.el,
103 by: 'lines'
104 })
105 results.forEach(s => Splitting({ target: s.words }));
106
107 // for every line
108 for (const [linePosition, lineArr] of results[0].lines.entries()) {
109 // create a new Line
110 const line = new Line(linePosition);
111 let cells = [];
112 let charCount = 0;
113 // for every word of each line
114 for (const word of lineArr) {
115 // for every character of each line
116 for (const char of [...word.querySelectorAll('.char')]) {
117 cells.push(
118 new Cell(char, {
119 position: charCount,
120 previousCellPosition: charCount === 0 ? -1 : charCount-1
121 })
122 );
123 ++charCount;
124 }
125 }
126 line.cells = cells;
127 this.lines.push(line);
128 this.totalChars += charCount;
129 }
130
131 // TODO
132 // window.addEventListener('resize', () => this.resize());
133 }
134 /**
135 * clear all the cells chars
136 */

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected