Skip to content

Commit

Permalink
コードをマシに
Browse files Browse the repository at this point in the history
  • Loading branch information
nakasyou authored Sep 16, 2023
1 parent dde1769 commit 9d1cef6
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/scripts/codeAnimation.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
class codeAnime {
constructor(element) {
const bodyCode = element.innerHTML.split("");
let visualCode = "";
let init = 0;
const addCode = () => {
if (init >= bodyCode.length) {
cancelAnimationFrame(addCode);
return;
}
visualCode += bodyCode[init];
element.innerHTML = visualCode;
init++;
setTimeout(() => {requestAnimationFrame(addCode);},2.5)
};
addCode();
const setCodeAnimation = element => {
const mainCode = Array.from(element.innerHTML)

let tmpCode = ''

let index = 0
const next = () => {
if (init < bodyCode.length) {
tmpCode += mainCode[index]
element.innerHTML = tmpCode
requestAnimationFrame(next)
}
}
next()
}

function callbackBuild() {
let divs = document.querySelectorAll("body > div,box");

for (let i = 0; i < divs.length;i++) {
new codeAnime(divs[i])
setCodeAnimation(divs[i])
}
}

0 comments on commit 9d1cef6

Please sign in to comment.