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

Method fx4

src/js/typeShuffle.js:269–306  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

267 }
268 }
269 fx4() {
270 const MAX_CELL_ITERATIONS = 30;
271 let finished = 0;
272 this.clearCells();
273
274 const loop = (line, cell, iteration = 0) => {
275 cell.cache = cell.state;
276
277 if ( iteration === MAX_CELL_ITERATIONS-1 ) {
278 cell.set(cell.original);
279
280 ++finished;
281 if ( finished === this.totalChars ) {
282 this.isAnimating = false;
283 }
284 }
285 else if ( cell.position === 0 ) {
286 cell.set(['*',':'][Math.floor(Math.random() * 2)]);
287 }
288 else {
289 cell.set(line.cells[cell.previousCellPosition].cache);
290 }
291
292 if ( cell.cache != ' ' ) {
293 ++iteration;
294 }
295
296 if ( iteration < MAX_CELL_ITERATIONS ) {
297 setTimeout(() => loop(line, cell, iteration), 15);
298 }
299 };
300
301 for (const line of this.lines) {
302 for (const cell of line.cells) {
303 setTimeout(() => loop(line, cell), Math.abs(this.lines.length/2-line.position)*400);
304 }
305 }
306 }
307 fx5() {
308 // max iterations for each cell to change the current value
309 const MAX_CELL_ITERATIONS = 30;

Callers 1

TypeShuffleClass · 0.95

Calls 1

clearCellsMethod · 0.95

Tested by

no test coverage detected